How to slice process itertools.product in python?
<p>I want to process a very large <code>itertools.product</code> object. The issue is something like this:</p>

<pre><code>import string
from itertools import product
text = string.lowercase[:] + string.uppercase[:] + '0123456789'
items = product(text, repeat=5)
for item in items:
    #do something
</code></pre>

<p>I know the <code>items</code>'s length is <code>62**5</code>. If I want to process the elements of <code>items</code> whose indices range from <code>300000</code> to <code>600000</code>, how to achieve this?</p>

<p>I have tried to convert the <code>itertools.product</code> to python list, like this:</p>

<pre><code>items = list(product(text, repeat=5))[300000:600000+1]
for item in items:
    #do something
</code></pre>

<p>but it seems the conversion has consumed a large amount of memory since I have been waiting for a long time for this convert, and finally gave it up.</p>

<p>I have this demand because I want to do this thing in python gevent, so I want to slice the large <code>itertool.product</code> to small items for gevent spawn.</p>