title: Python - iterating through list and dictionary to get a nested list output
body: <p>I have a dictionary <code>mydict</code> which contains some filenames as keys and text within them as values. </p>
  
  <p>I am extracting a list of words from the text in each file. Words are stored in a list <code>mywords</code>.</p>
  
  <p>I have tried the following.</p>
  
  <pre class="lang-py prettyprint-override"><code>mydict = {'File1': 'some text. \n Foo extract this. \n Bar extract this', 
  'File2': 'more text. \n Bar extract this too.'}
  mywords = ['Foo', 'Bar']
  mylist= []
  for k,v in mydict.items():
          for word in mywords:
              extracted = (re.findall('^ ' + word + ".*", v, flags=re.IGNORECASE|re.MULTILINE))
              mylist.append(extracted[:1])
  </code></pre>
  
  <p>This gives me</p>
  
  <pre class="lang-py prettyprint-override"><code>[[' Foo extract this. '],
   [' Bar extract this'],
   [],
   [' Bar extract this too.']]
  </code></pre>
  
  <p>However, I want the output to have 2 nested lists (for each file) instead of a separate list each time it searches a word in a file. </p>
  
  <p>Desired output:</p>
  
  <pre class="lang-py prettyprint-override"><code>[[' Foo extract this. '], [' Bar extract this']],
   [[], [' Bar extract this too.']]
  </code></pre>