bug_x

导航

 
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)

 

posted on 2018-07-06 00:01  bug_x  阅读(124)  评论(0编辑  收藏  举报