yhsjx = lambda col: [1] * col if col <= 2 else [1] + [yhsjx(col - 1)[x] + yhsjx(col - 1)[x + 1] for x in range(len(yhsjx(col - 1)) - 1)] + [1]
[print(yhsjx(x)) for x in range(1, 6)]
生成一個5階楊輝三角形
運行結果
/usr/local/bin/python3.7 /Users/yqcd/Downloads/bob_folder/pyFolder/test.py
[1]
[1, 1]
[1, 2, 1]
[1, 3, 3, 1]
[1, 4, 6, 4, 1]
Process finished with exit code 0
能不能減少爲1行呢?