Re: itertools.groupby
- From: Gordon Airporte <JHoover@xxxxxxx>
- Date: Mon, 28 May 2007 23:02:31 -0400
Paul Rubin wrote:
It chops up the iterable into a bunch of smaller ones, but the total
size ends up the same. "Telescope", "compact", "collapse" etc. make
it sound like the output is going to end up smaller than the input.
Good point... I guess I was thinking in terms of the number of iterators being returned being smaller than the length of the input, and ordered relative to the input - not about the fact that the iterators contain all of the objects.
There is also a dirty secret involved <wink>, which is that the
itertools functions (including groupby) are mostly patterned after
similarly named functions in the Haskell Prelude, which do about the
same thing. They are aimed at helping a similar style of programming,
so staying with similar names IMO is a good thing.
Ah - those horrible, intolerant Functionalists. I dig ;-).
But that is what groupby does, except its notion of uniqueness is
limited to contiguous runs of elements having the same key.
"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).
|
'''
"Each" seems to imply uniqueness here.
.
- Follow-Ups:
- Re: itertools.groupby
- From: Raymond Hettinger
- Re: itertools.groupby
- From: Carsten Haese
- Re: itertools.groupby
- From: Paul Rubin
- Re: itertools.groupby
- References:
- itertools.groupby
- From: 7stud
- Re: itertools.groupby
- From: Gordon Airporte
- Re: itertools.groupby
- From: Paul Rubin
- itertools.groupby
- Prev by Date: Patch to pydoc (partial) to handle encodings other than ascii
- Next by Date: Re: Is PEP-8 a Code or More of a Guideline?
- Previous by thread: Re: itertools.groupby
- Next by thread: Re: itertools.groupby
- Index(es):