def add(n, i): return n+i def test(): for i in range(4): yield i g = test() for n in [1, 10, 4]: g = (add(n, i) for i in g) # 0,1,2,3 +4 4,5,6,7 +4 8,9,10,11 +4 12,13,14,15 print(list(g))
python生成器面试题
最新推荐文章于 2023-06-25 11:01:43 发布
def add(n, i): return n+i def test(): for i in range(4): yield i g = test() for n in [1, 10, 4]: g = (add(n, i) for i in g) # 0,1,2,3 +4 4,5,6,7 +4 8,9,10,11 +4 12,13,14,15 print(list(g))