groupby

Bryan belred at gmail.com
Mon May 22 23:28:16 EDT 2006


can some explain why in the 2nd example, m doesn't print the list [1, 1, 1] 
which i had expected?


 >>> for k, g in groupby([1, 1, 1, 2, 2, 3]):
...     print k, list(g)
...
1 [1, 1, 1]
2 [2, 2]
3 [3]


 >>> m = list(groupby([1, 1, 1, 2, 2, 3]))
 >>> m
[(1, <itertools._grouper object at 0x00AAC600>), (2, <itertools._grouper object 
at 0x00AAC5A0>), (3, <itertools._grouper object at 0x00AAC5B0>)]
 >>> list(m[0][1])
[]
 >>>


thanks,

bryan




More information about the Python-list mailing list