1

I have a prime-yielder function called xprimes(start,stop) wich behaves like this:

>>> xpms = xprimes(2) #not specifying the stop yields primes forever.
>>> xpms.next()
2
>>> xpms.next()
3
>>> xpms.next()
5
>>> xpms.next()
7
>>> xpms.next()
11

And so on. I'd like to know if it is possible to store the state of any generator function in a variable such as if this example happens, where both xpms1 and xpms2 were held about to yield 13

>>> xpms1 = xpms; xpms2 = xpms;
>>> xpms1.next()
13
>>> xpms1.next()
17
>>> xpms1.next()
19
>>> xpms2.next()
13
Pedro
  • 1,121
  • 7
  • 16

0 Answers0