Grouping lists

Benji York benji at benjiyork.com
Fri Sep 9 13:31:51 EDT 2005


PyPK wrote:
> lst = [1,1,1,1,3,5,1,1,1,1,7,7,7]
> I want to group the list so that it returns groups such as
> [(0,3),4,5,(6,9),(10,12)]. which defines the regions which are similar.

You'll probably want to use "groupby" from the itertools module.  See 
http://docs.python.org/lib/itertools-functions.html
--
Benji York




More information about the Python-list mailing list