higher_func.py 794 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from typing import Callable
  2. def apply(func, objects):
  3. return [func(x) for x in objects]
  4. def compute(func_list, *args):
  5. return [func(x) for func in func_list for x in args]
  6. def compute_new(func_list, *args):
  7. lst = []
  8. value = 0
  9. for x in args:
  10. value = x
  11. for func in func_list:
  12. value = func(value)
  13. lst.append(value)
  14. return lst
  15. def filter_list(f: Callable, lst: list):
  16. pass
  17. """Для теста"""
  18. def square(num):
  19. return num ** 2
  20. def inc(num):
  21. return num + 1
  22. def dec(num):
  23. return num - 1
  24. def main():
  25. print(compute([inc, dec, square], 10, 20, 30, 40))
  26. print(compute_new([inc, square, dec], 10, 20, 30, 40))
  27. if __name__ == '__main__':
  28. main()