itertools.groupby

Paul Rubin http
Mon May 28 23:18:18 EDT 2007


Gordon Airporte <JHoover at fbi.gov> writes:
> "itertools.groupby_except_the_notion_of_uniqueness_is_limited_to-
> _contiguous_runs_of_elements_having_the_same_key()" doesn't have much
> of a ring to it. I guess this gets back to documentation problems,
> because the help string says nothing about this limitation:
> 
> '''
> class groupby(__builtin__.object)
>   |  groupby(iterable[, keyfunc]) -> create an iterator which returns
>   |  (key, sub-iterator) grouped by each value of key(value).
>   |
> '''

I wouldn't call it a "limitation"; it's a designed behavior which is
the right thing for some purposes and maybe not for others.  For
example, groupby (as currently defined) works properly on infinite
sequences, but a version that scans the entire sequence to get bring
together every occurrence of every key would fail in that situation.
I agree that the doc description could be reworded slightly.



More information about the Python-list mailing list