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 zero, so the while condition is immediately false, and the loop ends.for i in g: print(i).