title: Choose Python function to call based on a regex
body: <p>Is it possible to put a function in a data structure, without first giving it a name with <code>def</code>?</p>
  
  <pre><code># This is the behaviour I want. Prints "hi".
  def myprint(msg):
      print msg
  f_list = [ myprint ]
  f_list[0]('hi')
  # The word "myprint" is never used again. Why litter the namespace with it?
  </code></pre>
  
  <p>The body of a lambda function is severely limited, so I can't use them. </p>
  
  <p>Edit: For reference, this is more like the real-life code where I encountered the problem.</p>
  
  <pre><code>def handle_message( msg ):
      print msg
  def handle_warning( msg ):
      global num_warnings, num_fatals
      num_warnings += 1
      if ( is_fatal( msg ) ):
          num_fatals += 1
  handlers = (
      ( re.compile( '^&lt;\w+&gt; (.*)' ), handle_message ),
      ( re.compile( '^\*{3} (.*)' ), handle_warning ),
  )
  # There are really 10 or so handlers, of similar length.
  # The regexps are uncomfortably separated from the handler bodies,
  # and the code is unnecessarily long.
  
  for line in open( "log" ):
      for ( regex, handler ) in handlers:
          m = regex.search( line )
          if ( m ): handler( m.group(1) )
  </code></pre>