Merge two dictionaries
<p>I have something like this: </p>

<pre><code>Dict1 = {'a': "blabla", 'b': "gugu"}
Dict2 = {'a': "tadaa", 'b': "duduu"}
</code></pre>

<p>what I want to have is:</p>

<pre><code>Dict3 = {'tadaa': "blabla", 'duduu': "gugu"}
</code></pre>

<p>Iterate over one dictionary's keys and values, use the value as key in a new dictionary and use the key to pull the associated value out of the second dictionary. In <a href="https://docs.python.org/3.6/tutorial/datastructures.html#dictionaries" rel="nofollow">a single expression</a>:</p>

<pre><code>&gt;&gt;&gt; Dict1 = {'a': "blabla", 'b': "gugu"}
&gt;&gt;&gt; Dict2 = {'a': "tadaa", 'b': "duduu"}    
&gt;&gt;&gt; {v: Dict1[k] for k, v in Dict2.items()}
{'duduu': 'gugu', 'tadaa': 'blabla'}
</code></pre>

python python-2.7 python-3.x