title: map with lambda vs map with function - how to pass more than one variable to function?
body: <p>I wanted to learn about using <code>map</code> in python and a google search brought me to <a href="http://www.bogotobogo.com/python/python_fncs_map_filter_reduce.php" rel="nofollow">http://www.bogotobogo.com/python/python_fncs_map_filter_reduce.php</a> which I have found helpful.</p>
  
  <p>One of the codes on that page uses a for loop and puts <code>map</code> within that for loop in an interesting way, and the list used within the <code>map</code> function actually takes a list of 2 functions. Here is the code:</p>
  
  <pre><code>def square(x): 
      return (x**2)
  
  def cube(x):
      return (x**3)
  
  funcs = [square, cube]
  
  for r in range(5):
      value = map(lambda x: x(r), funcs)
      print value
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>[0, 0]
  [1, 1]
  [4, 8]
  [9, 27]
  [16, 64]
  </code></pre>
  
  <p>So, at this point in that tutorial, I thought "well if you can write that code with a function on the fly (lambda), then it could be written using a standard function using <code>def</code>". So I changed the code to this:</p>
  
  <pre><code>def square(x): 
      return (x**2)
  
  def cube(x):
      return (x**3)
  
  def test(x):
      return x(r)
  
  funcs = [square, cube]
  
  for r in range(5):
      value = map(test, funcs)
      print value
  </code></pre>
  
  <p>I got the same output as the first piece of code, but it bothered me that variable <code>r</code> was taken from the global namespace and that the code is not tight functional programming. And there is where I got tripped up. Here is my code:</p>
  
  <pre><code>def square(x): 
      return (x**2)
  
  def cube(x):
      return (x**3)
  
  def power(x):
      return x(r)
  
  def main():
      funcs = [square, cube]
      for r in range(5):
          value = map(power, funcs)
          print value
  
  if __name__ == "__main__":
      main()
  </code></pre>
  
  <p>I have played around with this code, but the issue is with passing into the function <code>def power(x)</code>. I have tried numerous ways of trying to pass into this function, but lambda has the ability to automatically assign <code>x</code> variable to each iteration of the list <code>funcs</code>.</p>
  
  <p><strong>Is there a way to do this by using a standard <code>def</code> function, or is it not possible and only lambda can be used?</strong> Since I am learning python and this is my first language, I am trying to understand what's going on here.</p>