New submission from Matt Gilson:
There is some odd behavior when unpacking the groups from an itertools.groupby
result. For example:
from itertools import groupby
from operator import itemgetter
inputs = ((x > 5, x) for x in range(10))
(_, a), (_, b) = groupby(inputs, key=itemgetter(0))
print(list(a))
print(list(b))
On CPython, this results in:
[]
[(True, 9)]
I would expect it to print out 2 empty lists since the second group would have
to be consumed to make sure that there isn't another value yielded from groupby
(If there was another value to yield, we'd get a ValueError since we couldn't
unpack the correct number of items).
This is the behavior that PyPy had prior to re-implementing to be consistent
with CPython in
https://bitbucket.org/pypy/pypy/commits/6093ff1a44e6b17f09db83aa80aea562a738c286
----------
messages: 293511
nosy: Matt Gilson
priority: normal
severity: normal
status: open
title: Odd behavior when unpacking `itertools.groupby`
type: behavior
versions: Python 3.3, Python 3.5
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue30346>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com