This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Loïc Le Loarer
Recipients Loïc Le Loarer
Date 2017-09-27.20:55:48
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
If I "list" the itertools groupby generator, then the sub generators of each groups are all empty except the last one.

import itertools as i
L = ['azerty','abcd','ac','aaa','z','baba','bitte','rhum','z','y']
g = list(i.groupby(L, lambda x: x[0]))
number_of_groups = len(g)
ans = 0
for k, v in g: # This doesn't work
#for k, v in i.groupby(L, lambda x: x[0]): # This works
    v = list(v)
    ans += 100*len(v)//number_of_groups
assert(ans == 163)
I don't understand why. Is my code broken ?

The need for saving the group generator first exists when I need the number of groups before walking thru the groups, like in the above example.

I have not been able to test to latest python versions, is the problem already fixed ?
Date User Action Args
2017-09-27 20:55:49Loïc Le Loarersetrecipients: + Loïc Le Loarer
2017-09-27 20:55:49Loïc Le Loarersetmessageid: <>
2017-09-27 20:55:49Loïc Le Loarerlinkissue31614 messages
2017-09-27 20:55:48Loïc Le Loarercreate