Why do I get a MemoryError with itertools.product?

后端 未结 3 475
再見小時候
再見小時候 2020-12-14 11:05

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+ (r27         


        
3条回答
  •  醉梦人生
    2020-12-14 11:43

    I think the problem could be that xrange returns its own special sort of object, which is not a normal iterable.

    xrange is implemented in such a way (as are lists) that you can iterate over the object many times, while you can iterate over a normal generator object only once. So perhaps something from this functionality is responsible for the memory error.

提交回复
热议问题