I would expect the following snippet to give me an iterator yielding pairs from the Cartesian product of the two input iterables:
$ python
Python 2.7.1+ (r271:86832, Apr 11 2011, 18:13:53)
[GCC 4.5.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import itertools
>>> one = xrange(0, 10**9)
>>> two = (1,)
>>> prods = itertools.product(one, two)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
MemoryError
Instead, I get a MemoryError
. But I thought that itertools.product
did not store the intermediate results in memory, so what's causing the MemoryError
?