在这个问题中,我使用Python生成器进行了无休止的序列.但是相同的代码在Python 3中不起作用,因为它似乎没有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())
Run Code Online (Sandbox Code Playgroud)