Re: Problem with itertools.groupby.

2006-05-25 Thread Fredrik Lundh
> itertools only looks for changes to the key value (the one returned by > operator.itemgetter(0) in your case); it doesn't sort the list for you. > > this should work: > >for k, g in itertools.groupby(sorted(vals), operator.itemgetter(0)): > print k, [i for i in g] footnote: to turn

Re: Problem with itertools.groupby.

2006-05-25 Thread Fredrik Lundh
[EMAIL PROTECTED] wrote: > What am I doing wrong here? > import operator import itertools vals = [(1, 11), (2, 12), (3, 13), (4, 14), (5, 15), > ... (1, 16), (2, 17), (3, 18), (4, 19), (5, 20)] for k, g in itertools.groupby(iter(vals), operator.itemgetter(0)): > ... p

Re: Problem with itertools.groupby.

2006-05-25 Thread Scott David Daniels
[EMAIL PROTECTED] wrote: > What am I doing wrong here? > import operator import itertools vals = [(1, 11), (2, 12), (3, 13), (4, 14), (5, 15), > ... (1, 16), (2, 17), (3, 18), (4, 19), (5, 20)] for k, g in itertools.groupby(iter(vals), operator.itemgetter(0)): > ... pr