title: Python: Reduce() and function as argument of function
body: <p>In Python3 I am Trying to figure out about reduce() and function as argument of function, or better passing a function as an argument of another one where the first one is not explicit see below</p>
  
  <p>given:</p>
  
  <pre><code># define a function `call` where you provide the function and the arguments
  def call(y,f):
      return f(y)
  
  # define a function that returns the square
  square = lambda x : x*x
  
  # define a function that returns the increment
  increment = lambda x : x+1
  
  # define a function that returns the cube
  cube = lambda x : x*x*x
  
  # define a function that returns the decrement
  decrement = lambda x : x-1
  
  # put all the functions in a list in the order that you want to execute them
  funcs = [square, increment, cube, decrement]
  
  #bring it all together. Below is the non functional part. 
  #in functional programming you separate the functional and the non functional parts.
  from functools import reduce # reduce is in the functools library
  print(reduce(call, funcs,1)) # output 7 , 2  res 124
  
  </code></pre>
  
  <p>why it doesnt work if </p>
  
  <p>I change</p>
  
  <pre><code>def call(y,f)
         f(y)
  
  </code></pre>
  
  <p>in</p>
  
  <pre><code>def call(f,y)
         f(y)
  
  </code></pre>
  
  <p>and gives out a  error:</p>
  
  <pre><code>................py", line 27, in call
      return f(y)
  
  TypeError: 'int' object is not callable
  </code></pre>