title: An elegant way of inserting multiple arguments
body: <p>I have this dictionary:  </p>
  
  <pre><code>local_commands_dict = {
      r"\b(listen)\b\s(\d+)": listen_for_connections
  }
  </code></pre>
  
  <p>Which contains a regex to match as key and a method variable as value.
  I am using the following code to navigate user input, into a command from the dictionary:</p>
  
  <pre><code>for cmd in local_commands_dict:
      regex = re.compile(cmd)
      match = regex.match(data)
      if match is not None:
          if regex.groups == 1:
              local_commands_dict[cmd]()
          elif regex.groups == 2:
              local_commands_dict[cmd](match.group(2))
          elif regex.groups == 3:
              local_commands_dict[cmd](match.group(2),match.group(3))
                      break
  </code></pre>
  
  <p>Where <code>data</code> is the user input. Is there any nicer way to navigate between the different amount of arguments? There must be, it's Python. </p>
  
  <p>Thanks!</p>