Advertisement
shinemic

respective_map

Oct 27th, 2019
439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.42 KB | None | 0 0
  1. from functools import reduce
  2.  
  3. funs = [
  4.     lambda x: x + 1,
  5.     lambda x: x * 2,
  6.     lambda x: x / 3,
  7.     lambda x: x ** 4,
  8. ]
  9.  
  10. operands = [4, 5, 6, 2]
  11.  
  12.  
  13. def zip_():
  14.     return list(map(lambda x: x[0](x[1]), zip(funs, operands)))
  15.  
  16.  
  17. def reduce_():
  18.     itfuns = iter(funs)
  19.     return reduce(lambda acc, x: acc.append(
  20.         next(itfuns)(x)) or acc, operands, [])
  21.  
  22.  
  23. print(zip_())
  24. print(reduce_())
  25.  
  26. # [5, 10, 2.0, 16]
  27. # [5, 10, 2.0, 16]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement