Discuss / Python / yanghui(这个是挺难的,琢磨很久)

yanghui(这个是挺难的,琢磨很久)

Topic source

霁天13

#1 Created at ... [Delete] [Delete and Lock User]

def yanghui(n): l = [1] while True: yield l l = [1] + [l[x] + l[x + 1] for x in range(len(l) - 1)] + [1] if len(l) > n: break

m = yanghui(6) for i in m: print(i)

output: [1] [1, 1] [1, 2, 1] [1, 3, 3, 1] [1, 4, 6, 4, 1] [1, 5, 10, 10, 5, 1]


  • 1

Reply