How do I map values to values with a common key in Python
<p>In the dictionaries below I want to check whether the value in aa matches the value in bb and produce a mapping of the keys of aa to the keys of bb.  Do I need to rearrange the dictionaries?  I import the data from a tab separated file, so I am not attached to dictionaries.  Note that aa is about 100 times bigger than bb (100k lines for aa), but this is to be run infrequently and offline.  </p>

<p>Input:</p>

<pre><code>aa = {1: 'a', 3: 'c', 2 : 'b', 4 : 'd'}
bb = {'apple': 'a', 'pear': 'b', 'mango' : 'g'}
</code></pre>

<p>Desired output (or any similar data structure):</p>

<pre><code>dd = {1 : 'apple', 2 : 'pear'}
</code></pre>
