A problem with itertools.groupby

Chris Angelico rosuav at gmail.com
Fri Dec 17 10:44:04 EST 2021


On Sat, Dec 18, 2021 at 2:32 AM ast <ast at invalid> wrote:
>
> Python 3.9.9
>
> Hello
>
> I have some troubles with groupby from itertools
>
> from itertools import groupby
>
> li = [grp for k, grp in groupby("aahfffddssssnnb")]
> list(li[0])
>
> []
>
> list(li[1])
>
> []
>
> It seems empty ... I don't understand why, this is
> the first read of an iterator, it should provide its
> data.
>

https://docs.python.org/3/library/itertools.html#itertools.groupby

Check the explanatory third paragraph :)

ChrisA


More information about the Python-list mailing list