On Sat, Jul 28, 2012 at 7:12 PM, Francesco Loffredo <f...@libero.it> wrote:
>
> My bad, now I'll RTFM again and I will study very carefully the operator and
> itertools modules.

I forgot to mention a gotcha about groupby's implementation. The
grouby object and the yielded _grouper objects share a single
iterator. Here's a (somewhat contrived) example of a mistake:

>>> groups = groupby(sorted(data, key=keyfunc), keyfunc)
>>> groups = list(groups)  #DON'T DO THIS
>>> groups
[((0, '3eA', 'Dupont', 'Juliette'), <itertools._grouper object at 0xb74734ec>),
 ((1, '3eA', 'Pop', 'Iggy'), <itertools._grouper object at 0xb74735cc>)]

>>> list(groups[0][1])  #EMPTY
[]
>>> list(groups[1][1])  #ONLY THE LAST ITEM
[(1, '3eA', 'Pop', 'Iggy', 5, 40.5, 60.0)]
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to