+ 1

Reset Generator

What is the proper way to reset a generator, such as if you want to reuse the same generator in two separate areas of your code? ... please assume that combining those two separate uses into one is not feasible/desired.

28th Jan 2018, 4:51 AM
N. Förster
N. Förster - avatar
2 Réponses
+ 7
It seems you can use itertools.tee() to make a second version of the generator: y = FunctionWithYield() y, y_backup = tee(y) for x in y: print(x) for x in y_backup: print(x) from https://stackoverflow.com/q/1271320
28th Jan 2018, 8:37 AM
David Ashton
David Ashton - avatar
+ 2
Thanks!
30th Jan 2018, 1:45 AM
N. Förster
N. Förster - avatar
Aujourd'hui en vedette
.
1 Votes
What?
0 Votes
HTML
0 Votes
Web
0 Votes
Quiz duel
0 Votes
FRC Coding?
1 Votes
help
0 Votes
AI
2 Votes
APIs
1 Votes