title: Getting Lists of Summed Nested Dictionary Values
body: <p>I am trying to write a part of program where the user inputs a Target Word (<code>targetWord = input()</code>), assigns a nested Dictionary with the key being the same as the input word.</p>
  
  <p>For example:</p>
  
  <pre><code>mainDict = {
      'x': {'one': 1, 'blue': 1, 'green' :1},
      'y': {'red': 1, 'blue': 2, 'two': 1},
      'z': {'one': 1, 'green': 1, 'red': 1}
  }
  </code></pre>
  
  <p>where all the values in the nested dictionary are assigned integers.</p>
  
  <p>The user may input <code>'x'</code>, to which the program will assign:</p>
  
  <pre><code>targetDict = mainDict['x']
  </code></pre>
  
  <p>The program should then allow the user to input words again, but this time every single word from input is appended to a lookup list, for example user inputs <code>'y'</code>, then <code>'z'</code>:</p>
  
  <pre><code>lookup = ['y', 'z']
  </code></pre>
  
  <p>Then the program should run through the nested dictionary and for every value with the corresponding key as in the <code>targetDict</code>, append just values to a new nested list and add whatever value the nested Dictionary values are. So the output of this section should be:</p>
  
  <pre><code>targetOutput = [[2], [1, 1]]
  </code></pre>
  
  <p>because in nested dict <code>'y'</code>, only <code>'blue'</code> was a common key, to which its value <code>2</code> was put in a list, then appended onto <code>targetOutput</code>. The same case with dict <code>'z'</code>, where the keys <code>'one'</code> and <code>'green'</code> were present in both <code>'x'</code> and <code>'z'</code>, putting their values, <code>1</code> and <code>1</code> into a nested list.</p>
  
  <p>Here is a representation of the dysfunctional code I have for:</p>
  
  <pre><code>targetOutput = []
  targetDict = mainDict[targetWord]
  for tkey in targetDict:
      tt = []
      for word in lookup:
          for wkey in primaryDict[word]:
              if tkey == wkey:
                  tt.append(targetDict[tkey])
  tl.append(sum(tt))
  
  
  print((pl))
  </code></pre>
  
  <p>The sum function at the end is because my actually final output should be the sum of the values in the nested list, akin to:</p>
  
  <pre><code>tl = [[2], [2]]
  </code></pre>
  
  <p>I am also trying to make the reverse happen, where in another list for every key in the lookup, it returns a nested list containing the sum of every value the <code>targetWord</code> dictionary also has a key for, like:</p>
  
  <pre><code>ll = [[2], [2]]
  </code></pre>
  
  <p>My question is, how do I fix my code so that it outputs the 2 above lists? I'm quite new with dictionaries.</p>