itertools.groupby

Gordon Airporte JHoover at fbi.gov
Mon May 28 17:19:00 EDT 2007


7stud wrote:
> Bejeezus.  The description of groupby in the docs is a poster child
> for why the docs need user comments.  Can someone explain to me in
> what sense the name 'uniquekeys' is used this example:
> 

This is my first exposure to this function, and I see that it does have 
some uses in my code. I agree that it is confusing, however.
IMO the confusion could be lessened if the function with the current 
behavior were renamed 'telescope' or 'compact' or 'collapse' or 
something (since it collapses the iterable linearly over homogeneous 
sequences.)
A function named groupby could then have what I think is the clearly 
implied behavior of creating just one iterator for each unique type of 
thing in the input list, as categorized by the key function.



More information about the Python-list mailing list