title: How to return a list of dictionaries from the match of regex.findall?
body: <p>I'm working on several hundreds of documents and I'm writing a function that will find specific words and its values and returns a list of dictionaries. </p>
  
  <p>I'm looking specifically for a piece of specific information ('city' and the number that refers to it). However, in some documents, I have one city, and in others, I might have twenty or even one hundred, so I need something very generic. </p>
  
  <p>A text example (the parenthesis are messed up like this):</p>
  
  <pre><code>text = 'The territory of modern Hungary was for centuries inhabited by a succession of peoples, including Celts, Romans, Germanic tribes, Huns, West Slavs and the Avars. The foundations of the Hungarian state was established in the late ninth century AD by the Hungarian grand prince Árpád following the conquest of the Carpathian Basin. According to previous census City: Budapest (population was: 1,590,316)Debrecen (population was: 115,399)Szeged (population was: 104,867)Miskolc (population was: 109,841). However etc etc'
  </code></pre>
  
  <p>or</p>
  
  <pre><code>text2 = 'About medium-sized cities such as City: Eger (population was: 32,352). However etc etc'
  </code></pre>
  
  <p>Using regex I found the string that I'm looking for:</p>
  
  <pre><code>p = regex.compile(r'(?&lt;=City).(.*?)(?=However)')
  m = p.findall(text)
  </code></pre>
  
  <p>Which returns the whole text as a list. </p>
  
  <pre><code>[' Budapest (population was: 1,590,316)Debrecen (population was: 115,399)Szeged (population was: 104,867)Miskolc (population was: 109,841). ']
  </code></pre>
  
  <p>Now, this is where I'm stuck and I don't know how to proceed. Should I use regex.findall or regex.finditer? </p>
  
  <p>Considering that the amount of 'cities' varies in the documents, I would like to get a list of dictionaries back. If I run in text 2, I would get:</p>
  
  <pre><code>d = [{'cities': 'Eger', 'population': '32,352'}] 
  </code></pre>
  
  <p>If I run in text one:</p>
  
  <pre><code>d = [{'cities': 'Szeged', 'population': '104,867'}, {'cities': 'Miskolc': 'population': 109,841'}]
  </code></pre>
  
  <p>I really appreciate any help, guys!</p>