123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- from typing import Callable
- def get_math_func(operation: str) -> Callable[[int, int], int]:
- def add(a: int, b: int) -> int:
- return a + b
- def subtract(a: int, b: int) -> int:
- return a - b
- if operation == "+":
- return add
- elif operation == "-":
- return subtract
-
- def create_accumulator(st=0):
- counter = st
- def inner(x):
- nonlocal counter
- counter += x
- return counter
- return inner
- def multiply(st):
- def inner(x):
- nonlocal st
- return x*st
- return inner
- from datetime import datetime
- from time import perf_counter
- def timer():
- start = perf_counter()
-
- def inner():
- return perf_counter() - start
-
- return inner
- def add(a, b):
- return a + b
- def counter(func):
- count = 0
- def inner(*args, **kwargs):
- nonlocal count
- count += 1
- print(f"Функция {func.__name__} вызывалась {count} раз")
- return func(*args, **kwargs)
- return inner
- def create_dict():
- count = 0
- my_dict = {}
- def inner(foo):
- nonlocal count
- count += 1
- my_dict.update({count: foo})
- return my_dict
- return inner
-
- f_1 = create_dict()
- print(f_1('hello'))
- print(f_1(100))
- print(f_1([1, 2, 3]))
-
-
-
|