Python採用List【列表生成式】實現【楊輝三角】生成器

實現: # -*- coding: utf-8 -*- def triangles(): n, b = 10, [1] while n > 0: yield b b = [sum(i) for i in zip([0]+b,b+[0])] n = n - 1 return 'done' 測試: n = 0 for t in
相關文章
相關標籤/搜索