[Python-Help] (fwd)

Steven Bethard steven.bethard at gmail.com
Sun Dec 5 10:55:24 CET 2004


Craig Ringer wrote:
> As you can see, it's much easier to work with data in lists. Some of the
> other methods, like list.sort() and list "slices" will also be useful to
> you, but I'll let you figure out the details ;-) . 

Something else that might be useful to you if you're using Python 2.4:

 >>> lst = [1, 2, 2, 3, 4, 5, 5, 5, 6, 7, 8]
 >>> import itertools
 >>> for value, values in itertools.groupby(lst):
... 	print value, list(values)
... 	
1 [1]
2 [2, 2]
3 [3]
4 [4]
5 [5, 5, 5]
6 [6]
7 [7]
8 [8]

Steve



More information about the Python-list mailing list