[issue31614] can't list groupby generator without breaking the sub groups generators
Raymond Hettinger
report at bugs.python.org
Wed Sep 27 17:29:33 EDT 2017
Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:
Except for display the last few elements, this is the documented and intended behavior: ( https://docs.python.org/3/library/itertools.html#itertools.groupby ):
'''
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:
groups = []
uniquekeys = []
data = sorted(data, key=keyfunc)
for k, g in groupby(data, keyfunc):
groups.append(list(g)) # Store group iterator as a list
uniquekeys.append(k)
'''
The display of the last few elements isn't supposed to happen. That is being fixed so that all of the subiterator results are empty when the parent iterator is exhausted.
----------
assignee: -> rhettinger
nosy: +rhettinger
resolution: -> not a bug
stage: -> resolved
status: open -> closed
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31614>
_______________________________________
More information about the Python-bugs-list
mailing list