def compute_current(x, n, z):
# some computation here
def crunch(x, n):
current = x
z = yield current
while True:
current = compute_current(current, n, z)
z = yield current
c = crunch(x=10)
next(c)
new_x = crunch.send(some_z)
newer_x = crunch.send(some_other_z)
...
如果事先不知道z值的列表,您可能会为此尝试coroutine:
相关问题 更多 >
编程相关推荐