In this question, I have an endless sequence using Python generators. But the same code doesn't work in Python 3 because it seems there is no next()
function. What is the equivalent for the next
function?
def updown(n):
while True:
for i in range(n):
yield i
for i in range(n - 2, 0, -1):
yield i
uptofive = updown(6)
for i in range(20):
print(uptofive.next())
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…