python: ex2: add solution

This commit is contained in:
Bruno BELANYI 2022-11-21 16:21:36 +01:00
parent 0a13e7b6a5
commit 935d9df675

25
python/ex2.py Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env python
from copy import copy
def f(n: int) -> list[list[int]]:
if n == 0:
return []
if n == 1:
return [[1]]
res = f(n - 1)
res.append(copy(res[-1]))
res[-1].append(n)
return res
def main():
for i in range(5):
print(f"f({i})={f(i)}")
if __name__ == "__main__":
main()