L
Lacrima
Hello!
I am quite new to Python and I have maybe simple (or maybe not)
question.
Is it possible to restart generator when it is exhausted?
For example:
File "<pyshell#31>", line 1, in <module>
g.next()
StopIterationWhat should I do to get the initial state of g? So if I do again g.next
() I receive 'a'.
If it is not possible what are common techniques to use iterator or
generator objects that allow restarting when it is needed?
With regards,
Max
(sorry if my English isn't very proper)
I am quite new to Python and I have maybe simple (or maybe not)
question.
Is it possible to restart generator when it is exhausted?
For example:
Traceback (most recent call last):a = ['a', 'b', 'c']
g = (i for i in a)
g.next() 'a'
g.next() 'b'
g.next() 'c'
g.next()
File "<pyshell#31>", line 1, in <module>
g.next()
StopIterationWhat should I do to get the initial state of g? So if I do again g.next
() I receive 'a'.
If it is not possible what are common techniques to use iterator or
generator objects that allow restarting when it is needed?
With regards,
Max
(sorry if my English isn't very proper)