You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi Ramil, itertools.product() expect its argument to be finite iterables, it needs to keep all their elements in memory anyway at it "cycles around" to produce all possible pairs.
Basically, product(x(1), x(2)) is equivalent to product(tuple(x(1)), tuple(x(2))).
I see that the documentation does not mention that the arguments must be finite, could you open a PR to improve it?
Updated the docs to note that inputs are fully consumed before the iterator is run.
FYI, notes on infinite iterable inputs likely belong the FAQs because they aren't specific to product(). Similar effects would be seen with list(x(1)), sorted(x(1)), set(x(1)), tuple(x(1)), etc.
Activity
stsouko commentedon May 28, 2020
remilapeyre commentedon May 28, 2020
Hi Ramil, itertools.product() expect its argument to be finite iterables, it needs to keep all their elements in memory anyway at it "cycles around" to produce all possible pairs.
Basically, product(x(1), x(2)) is equivalent to product(tuple(x(1)), tuple(x(2))).
I see that the documentation does not mention that the arguments must be finite, could you open a PR to improve it?
rhettinger commentedon May 28, 2020
New changeset cfc6ce4 by Ramil Nugmanov in branch 'master':
bpo-40806: Clarify that itertools.product immediately consumes its inpt (GH-20492)
cfc6ce4
rhettinger commentedon May 28, 2020
Updated the docs to note that inputs are fully consumed before the iterator is run.
FYI, notes on infinite iterable inputs likely belong the FAQs because they aren't specific to product(). Similar effects would be seen with list(x(1)), sorted(x(1)), set(x(1)), tuple(x(1)), etc.
rhettinger commentedon May 28, 2020
New changeset e4cc3a7 by Miss Islington (bot) in branch '3.9':
bpo-40806: itertools.product immediately consumes its inputs (GH-20492) (GH-20498)
e4cc3a7