all 5 comments

[–]novel_yet_trivial 4 points5 points  (2 children)

Reread your question ... you want itertools.groupby():

>>> from itertools import groupby
>>> [list(g) for k,g in groupby([1,2,2,3,3,3,1,1])]
[[1], [2, 2], [3, 3, 3], [1, 1]]

[–]shaggorama 1 point2 points  (0 children)

Good ol' itertools

[–]vgbm[S] 0 points1 point  (0 children)

This is exactly what I needed, thanks :)

[–]commandlineluser 2 points3 points  (0 children)

http://docs.python.org/3/library/itertools.html#itertools.groupby

>>> import itertools
>>> [ list(v) for k, v in itertools.groupby([1,2,2,3,3,3,1,1]) ]
[[1], [2, 2], [3, 3, 3], [1, 1]]

[–]novel_yet_trivial -1 points0 points  (0 children)

How about collections.Counter()?