title: Automatic list generation; Python
body: <p>I apologise in advance for having such an vague title, but it's hard for me to conceptualise the problem precisely. </p>
  
  <p>I have a script that checks if a certain <code>name</code> is in a text. If the name is in the text, the script appends a <code>1</code> to a list specifically dedicated to that <code>name</code>, and if it's not in the text it appends a <code>0</code>.</p>
  
  <p>It looks like this: </p>
  
  <pre><code>import re
  import csv
  from itertools import izip
  
  names = ['peter', 'john', 'thomas', 'george']
  texts = ['peter is awesome', 'john is lazy', 'thomas is thomas','george is curious']
  
  peter_matched = []
  john_matched = []
  thomas_matched = []
  george_matched = []
  
  for text in texts:
      for name in names:
          if name == 'peter':
              if re.match(name, text):
                  peter_matched.append(1)
              else:
                  peter_matched.append(0)
          if name == 'john':
              if re.match(name, text):
                  john_matched.append(1)
              else:
                  john_matched.append(0)
          if name == 'thomas':
              if re.match(name, text):
                  thomas_matched.append(1)
              else:
                  thomas_matched.append(0)
          if name == 'george':
              if re.match(name, text):
                  george_matched.append(1)
              else:
                  george_matched.append(0)
  
  with open('output_names.csv', 'wb') as f:
          w = csv.writer(f)
          w.writerows(izip(texts, peter_matched, john_matched, thomas_matched, george_matched))
  </code></pre>
  
  <p>Now as you can see, it's an ugly mishmash of <code>if/else</code> statements. What's even more problematic, is that I have to create a separate dedicated list for every <code>name</code> to hold the matched information and then write it into a <code>.csv</code>. In my real script I would need to cross-reference thousands of texts and hundreds of names, so writing a dedicated <code>name_matched</code> list for every item is not exactly a fun task. </p>
  
  <p>So my question is: is it possible to tell Python to generate these lists automatically by taking an item's name from the <code>names</code> list and appending it to some pre-existing string, like <code>_matched</code>. </p>
  
  <p>In other words, I would like the lists <code>peter_matched</code>, <code>john_matched</code>, etc. to be created automatically.</p>
  
  <p>Thanks in advance!</p>