Python 列表表达式 ,迭代器(2) Yield

1yield 暂存为list

   def max_generator(numbers):
    current_max = 0
    for i in numbers:
        current_max = max(i, current_max)
        yield current_max;


a = [3, 4, 6, 2, 1, 9, 0, 7, 5, 8]
results = list(max_generator(a))
print(results)

猜你喜欢

转载自www.cnblogs.com/cbugs/p/9271476.html