Print a list of every combination of dictionary keys with the associated sum of the key values to the right
<p>I have several dictionaries and I want to print a table where each row is a unique combination of the keys in all dictionaries.  For each row, I also want to print the sum of the values for the keys in that particular combination.</p>

<p>So, if I have these dictionaries:</p>

<pre><code>dict1 = {"Main": 8, "Optional": 6, "Obscure": 4}
dict2 = {"Global": 8, "Regional": 4, "Local": 2}
...
</code></pre>

<p>The output would look like this (sorted by sum highest to lowest):</p>

<pre><code>Main, Global, 16
Optional, Global, 14
Main, Regional, 12
Obscure, Global, 12
Main, Local, 10
Optional, Regional, 10
Optional, Local, 8
Obscure, Regional, 8
Obscure, Local, 6
</code></pre>

<p>From what I've read, itertools.product will be what I'm looking for, but none of the existing questions are quite my use case and I'm struggling to even get started.</p>

<p>Any help would be appreciated.</p>

<p>Thanks</p>

<p>I think this would be something like:</p>

<pre><code>import itertools

dict1 = {"Main": 8, "Optional": 6, "Obscure": 4}
dict2 = {"Global": 8, "Regional": 4, "Local": 2}

merged = {'{}, {}'.format(prod[0], prod[1]): dict1[prod[0]] + dict2[prod[1]] 
          for prod in itertools.product(dict1, dict2)}

for k, v in merged.items():
    print('{}: {}'.format(k, v))
</code></pre>

<p>Output:</p>

<pre><code>Optional, Regional: 10
Main, Regional: 12
Optional, Local: 8
Main, Global: 16
Optional, Global: 14
Main, Local: 10
Obscure, Regional: 8
Obscure, Global: 12
Obscure, Local: 6
</code></pre>

python dictionary product itertools cartesian-product