g=test() for n in [1,10]: g=(add(n,i) for i in g) # 生成器表达式
# 当遇见这种问题的时候 先将循拆开 # for循环套生成器表达式 # n = 1 # g=(add(n,i) for i in g) # test() # n = 10 # g=(add(n,i) for i in g) # (add(n,i) for i in g)
# 2 带入方程 # g=(add(n,i) for i in test()) # g=(add(n,i) for i in (add(10,i) for i in test())) # n = 10 # g=(add(n,i) for i in (add(10,(0,1,2,3)) # n = 10 # g=(add(10,i) for i in (10,11,12,13)) # 20,21,22,23 print(list(g)) # 开始执行
g=test() for n in [1,10,5]: g=(add(n,i) for i in g) # 生成器表达式
# n = 1 # g=(add(n,i) for i in test()) # n = 10 # g=(add(n,i) for i in (add(n,i) for i in test())) # n = 5 # g=(add(n,i) for i in (add(n,i) for i in (add(n,i) for i in test()))) # g=(add(n,i) for i in (add(n,i) for i in (add(n,i) for i in (0,1,2,3)))) # g=(add(n,i) for i in (add(n,i) for i in (5,6,7,8))) # g=(add(n,i) for i in (10,11,12,13) # 15,16,17,18 print(list(g)) # 开始执行