Найти в Дзене
10 подписчиков

📑 Function Dictionary

📑 Task
1) What object is created by the first line of the program?
2) Rewrite the function so that the numbers from 0 to 3 are raised to the 2nd power

f_dict = lambda n: {_: lambda x, y=_: x ** y for _ in range(n + 1)}
for _ in f_dict(n=3):
print(_, f_dict(n=3)[_](2))

📑 Answer
1) The result is a function that creates a dictionary of functions
2)

f_dict = lambda n: {_: lambda x, y=_: y ** x for _ in range(n + 1)}
for _ in f_dict(n=3):
print(_, f_dict(n=3)[_](2))
📑 Function Dictionary python-puzzles.blogspot.com/...tml 📑 Task 1) What object is created by the first line of the program?
Около минуты