Does Python have a method similar to Haskell's group?
What I am looking for is a method that will group common elements together like so:
foo([1,2,2,3,3,3,1,1]) = [[1], [2,2], [3,3,3], [1,1]]
Does Python have a built in method which can do something like this or would I have to implement this myself?
5 comments · 100% upvoted · other discussions
Reread your question ... you want
itertools.groupby():shaggorama 2 points · Jan 2016 · Github username
Good ol' itertools
vgbm [OP] 1 points · Jan 2016
This is exactly what I needed, thanks :)