title: Determining the number of parameters in a lambda
body: <p>I am wondering if there is a way to determine (given a variable containing a lambda) the number of parameters the lambda it contains.  The reason being, I wish to call a function conditionally dependent on the number of parameters.</p>
  
  <p>What I'm looking for</p>
  
  <pre><code>def magic_lambda_parameter_counting_function(lambda_function):
      """Returns the number of parameters in lambda_function
  
      Args:
          lambda_function - A lambda of unknown number of parameters
      """
  </code></pre>
  
  <p>So I can do something like</p>
  
  <pre><code>def my_method(lambda_function):
  
      # ... 
      # (say I have variables i and element)
  
      parameter_count = magic_lambda_parameter_counting_function(lambda_function)
  
      if parameter_count == 1:
          lambda_function(i)
      elif parameter_count == 2:
          lambda_function(i, element)
  </code></pre>