Possible Duplicate:
Reseting generator object in Python
I often have the following problem in python: I have a generator which I am using in several calls to compute different values, like this:
mygenerator = generate_data()
value1 = compute1(mygenerator)
value2 = compute2(mygenerator)
The problem is, of course, that compute2 will find no data, since the generator has been consumed. So I am forced to "listize" the generator:
mygenerator = generate_data()
mylist = listize_generator(mygenerator)
value1 = compute1(mylist)
value2 = compute2(mylist)
Is there another method to solve this problem?