TelenkovDmitry 4 meses atrás
pai
commit
1eb51b35b9
1 arquivos alterados com 47 adições e 0 exclusões
  1. 47 0
      courses/python_func/higher_func.py

+ 47 - 0
courses/python_func/higher_func.py

@@ -0,0 +1,47 @@
+from typing import Callable
+
+
+
+def apply(func, objects):
+    return [func(x) for x in objects]
+
+
+def compute(func_list, *args):
+    return [func(x) for func in func_list for x in args]
+
+
+def compute_new(func_list, *args):
+    lst = []
+    value = 0
+    for x in args:
+        value = x
+        for func in func_list:
+            value = func(value)
+        lst.append(value)
+    
+    return lst
+
+
+def filter_list(f: Callable, lst: list):
+    pass
+
+
+"""Для теста"""
+def square(num):
+    return num ** 2
+
+def inc(num):
+    return num + 1
+
+def dec(num):
+    return num - 1
+
+
+
+def main():
+    print(compute([inc, dec, square], 10, 20, 30, 40))
+    print(compute_new([inc, square, dec], 10, 20, 30, 40))
+
+if __name__ == '__main__':
+    main()
+