 <p>I would approach this as follows:</p> <pre><code>from collections import defaultdict # using defaultdict makes the sums easier correlations = defaultdict(int) # default to int (i.e. 0) for i1, i2, correl in strScoresDict: # loop through data correlations[i1] += correl # add score for first item correlations[i2] += correl # and second item output = sorted(correlations, key=lambda x: correlations[x], reverse=True) # sort keys by value </code></pre> <p>Note, however, that the output is </p> <pre><code>output == ['item2', 'item1', 'item4', 'item3'] </code></pre> <p>As the total correlations are</p> <pre><code>{'item1': 220, 'item3': 100, 'item2': 240, 'item4': 200} </code></pre> <p>You can <a href="http://docs.python.org/2/library/collections.html#collections.defaultdict" rel="nofollow">read about <code>defaultdict</code> here</a>.</p>