最佳答案
在 这个问题中,我使用 Python 生成器得到了无穷无尽的序列。但是同样的代码在 Python3中不起作用,因为它似乎没有 next()函数。next函数的等价物是什么?
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())