作者:互粉-结局_596 | 来源:互联网 | 2023-05-17 23:28
def yanghui():
L = [1]
while True:
yield L
if len(L)==1:
L.append(1)
else:
# for i in range(0,len(L)-1):
# temp[i] = L[i]+L[i+1]
temp = [L[i] +L[i+1] for i in range(0,len(L)-1)]
L = [1]+temp+[1]
测试代码:
#!/usr/bin/env python3 # -*- coding: utf-8 -*- 'a test module' __author__ = 'Aran Li' import def_yanghui def testyh(n): re= [] count = 0 for t in def_yanghui.yanghui(): print(t) re.append(t) count = count +1 if count == n: break print(re)
输出会出现[1]变成[1,1],排查不到原因