Python loop generator
Looks like I’m missing something with for loop generators…
I deliberately made this simple code to test what was happening when I converted my list comprehensions to generators.
It showed that the generator var can’t be used more than once:
lst = (1,2,3) plus = (i+1 for i in lst) for i in plus: print(i) for i in plus: print(i)
2 3 4
What I expected:
It outputs the above twice.
What I want to know:
What is the reason for the generator var only being usable once?