I'd like to use a walrus operator with a simple generator in a while loop
def gen():
for i in range(5):
yield i
yield 10
g = gen()
while i := next(g):
print(i)
I expect the output to be:
0
1
2
3
4
10
However it's not printing anything. I'm aware I can do this in a for loop:
for i in gen():
print(i)
I'm not interested in the output being exact. I want a simple example of using generators with walrus operators.
gen() is returning 0 on the first iteration. range(1, 5) to set range to go from 1 to 5. I also updated 10 to None else the generator runs out and throws Ex
output: