Grouping elements into a list
I want to group elements into a list of list based on the indexing Starting with the first position in data, go until the next False. That's a grouping. Continue until the last element.
data = ['a','b','c','d','e','f']
indexer = [True, True, False, False, True, True]
Outcome would be:
[['a','b','c'], ['d'], ['e','f'] ]
Is itertools groupby the right solution? I'm a little confused about how to implement it.
Comments
Post a Comment