|
|
|
|
|
by ummonk
1834 days ago
|
|
Yes, but that's the case with all the functional approaches proposed. If Python were focused on functional programming it would have a utility function for this similar to itertools.groupby (but with indices in an array instead of keys in a dictionary). |
|
itertools.groupby doesn’t return a dictionary, it returns an iterator of (key, (iterator that produces values)) tuples. It sounds, though, like you want something like:
Then you could do this with something like: