我希望下面的代码片段给我一个迭代器,从两个输入迭代的笛卡尔积中产生对:
$ 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
相反,我得到一个MemoryError
. 但我认为itertools.product
没有将中间结果存储在内存中,那么是什么原因造成的MemoryError
?