title: Call functions in Python Nested List
body: <p>I need to iterate over nested lists in python, where the list items are function calls (first item in list is the function, any remaining items are the arguments to that function).
  These arguments can also themselves be functions with arguments, hence the nesting. A list can also contain a single function with no arguments.
  Like so:
  <code>['foo','arg1','arg2']</code>
  Or:
  <code>[['foo','arg1','arg2'],['bar'],['baz','arg1']]</code>
  Or:
  <code>['foo','arg1',['baz','arg1']]</code>
  Etc.</p>
  <p>Here's an example using fictitious sum and product functions... Sum adds, Product multiplies; If we evaluated the functions we'd get 10.</p>
  <p>['sum',['product',2,3],4]</p>
  <p>I can just pass the function and arguments to another function that does the actual 'calling' of my safe functions, but I'm having trouble actually iterating over the list recursively.
  Here's a sad attempt:</p>
  <pre><code>def process_list(l):
          if isinstance(l,list):
              results = []
              for item in l:
                  if isinstance(item,list):
                      func = item[0]
                      args = item[1:]
                      for idx, arg in enumerate(args):
                          if isinstance(arg,list):
                              args[idx] = process_list(arg)
                      results.append(function_caller_result(func,args)) #what if that's a list?
                  else:
                      results.append(item)
              return results
          return l
  
  
  </code></pre>
  <p>Any help here would be greatly appreciated! Thanks in advance! :)</p>