ptmcg at austin.rr._bogus_.com
Tue May 23 08:01:43 CEST 2006
"Bryan" <belred at gmail.com> wrote in message
news:mailman.6100.1148362738.27775.python-list at python.org...
> George Sakkis wrote:
> > "The returned group is itself an iterator that shares the underlying
> > iterable with groupby(). Because the source is shared, when the groupby
> > object is advanced, the previous group is no longer visible. So, if
> > that data is needed later, it should be stored as a list"
> > George
> i read that description in the docs so many times before i posted here.
> i read it about 10 more times, i finally get it. there's just something
> the wording that kept tripping me up, but i can't explain why :)
So here's how to save the values from the iterators while iterating over the
>>> m = [(x,list(y)) for x,y in groupby([1, 1, 1, 2, 2, 3])]
[(1, [1, 1, 1]), (2, [2, 2]), (3, )]
More information about the Python-list