Python: Add Values and Remove Entry for Tuple Permutations in a Dictionary
<p>I have a dictionary where the key is a tuple. Some of these tuples are permutations of each other (e.g. <code>(1, 2)</code> vs <code>(2, 1)</code>). I want to add the value of one permutation to the other, and then get rid of the second permutation. </p>

<pre><code>d = {(1, 3): 14, (1, 4): 13, (1, 2): 10, (11, 11): 19, (3, 1): 50, (4, 1): 5, ...}
</code></pre>

<p>should be </p>

<pre><code>{(1, 3): 64, (1, 4): 18, (1, 2): 10, (11, 11): 19, ...}
</code></pre>

<p>I thought about sorting them and then doing something based on position in the dictionary, but this is not very easy to scale up. Input is welcome!</p>