title: Capturing named groups in regex with re.findall
body: <p>When I was trying to answer this question: <a href="https://stackoverflow.com/questions/25628412/regex-to-split-ages-and-values-in-python">regex to split %ages and values in python</a> I noticed that I had to re-order the groups from the result of findall. For example:</p>
  
  <pre><code>data = """34% passed 23% failed 46% deferred"""
  result = {key:value for value, key in re.findall('(\w+)%\s(\w+)', data)}
  print(result)
  &gt;&gt;&gt; {'failed': '23', 'passed': '34', 'deferred': '46'}
  </code></pre>
  
  <p>Here the result of the findall is:</p>
  
  <pre><code>&gt;&gt;&gt; re.findall('(\w+)%\s(\w+)', data)
  &gt;&gt;&gt; [('34', 'passed'), ('23', 'failed'), ('46', 'deferred')]
  </code></pre>
  
  <p>Is there a way to change/specify the order of the groups that makes <strong>re.findall return</strong>:</p>
  
  <pre><code>[('passed', '34'), ('failed', '23'), ('deferred', '46')]
  </code></pre>
  
  <p>Just to clarify, the question is: </p>
  
  <p>Is it possible to specfic the order or re-order the groups for the return of the re.findall function? </p>
  
  <p>I used the example above to create a dictionary to provide a reason/use case for when you would want to change the order (making key as value and value as key)</p>
  
  <p>Further clarification:</p>
  
  <p>In order to handle groups in larger more complicated regexes, you can name groups, but those names are only accessible when you do a re.search pr re.match. From what I have read, findall has a fixed indices for groups returned in the tuple, The question is anyone know how those indices could be modified. This would help make handling of groups easier and intuitive.</p>