title: Lookup values from itemgetter in a dict
body: <p>I have a list of tuples that I'm trying to sort.  The tuples contain strings:</p>
  <pre><code>connectionsList = [('C', 'B'), ('A', 'C'), ('D', 'B'), ('C','D')]
  </code></pre>
  <p>The strings in the tuples have numeric values stored in a dict:</p>
  <pre><code>valuesDict = {'A':3, 'B':5, 'C':1, 'D':2}
  </code></pre>
  <p>What I'd like to do is sort the list by the sum of the values in the dict for the tuples.  Desired output for this toy example would be:</p>
  <pre><code>[(C,D), (A,C), (C,B), (D,B)]
  </code></pre>
  <p>which would have the sums of:</p>
  <pre><code>[3, 4, 6, 7]
  </code></pre>
  <p>Using itemgetter, I can sort alphabetically by position:</p>
  <pre><code>sortedView = sorted(connectionsList, key=itemgetter(0,1))
  </code></pre>
  <p>However, I'm having trouble looking up the values from <code>itemgetter</code> in the <code>dict</code>.  Running this:</p>
  <pre><code>sortedView = sorted(connectionsList, key=valuesDict[itemgetter(0)] + valuesDict[itemgetter(1)])
  </code></pre>
  <p>gives a dict error of <code>KeyError: operator.itemgetter(0)</code>.</p>
  <p>How do I create a sort based on the values in the <code>dict</code>?</p>