title: How to get group name of match regular expression in Python?
body: <p>Question is very basic whatever I do not know how to figure out group name from match. Let me explain in code:</p>
  
  <pre><code>import re    
  a = list(re.finditer('(?P&lt;name&gt;[^\W\d_]+)|(?P&lt;number&gt;\d+)', 'Ala ma kota'))
  </code></pre>
  
  <p>How to get group name of <code>a[0].group(0)</code> match - assume that number of named patterns can be larger? </p>
  
  <p>Example is simplified to learn basics.</p>
  
  <p>I can invert match <code>a[0].groupdict()</code> but it will be slow.</p>