-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Generators" section misleads about the ability to iterate generatiors multiple times #8
Comments
@SyberiaK in Python, For instance, in the generator example (given below), when the for loop breaks at i == 3, the generator "remembers" that iteration and continues from 4 when you convert it to a list. gen = (i for i in range(10))
for i in gen:
print(i)
if i == 3:
break
print(list(gen)) Output:
However, gen= range(10)
for i in gen:
print(i)
if i == 3:
break
print(list(gen)) Output:
While |
That's not true. After the first go-through the generator becomes empty.
Also... making this kind of generator from
range
is kinda a wacky idea. You can just use the range itself, which also acts like a generator and saves some additional memory.And it can actually be iterated multiple times.
The text was updated successfully, but these errors were encountered: