Я согласен с Алексом о необходимости разоблачения вещей как новичка и о том, чтобы перейти к более кратким / абстрактным / опасным конструкциям позже.
Для справки, я размещаю здесь версию со списком, поскольку Пол, похоже, не работает.
>>> d1 = {'a':'alpha', 'b':'bravo', 'c':'charlie', 'd':'delta'}
>>> d2 = {'alpha':'male', 'delta':'faucet', 'echo':'in the valley'}
>>> d3 = dict([(x, d2[d1[x]]) for x in d1**.keys() **if d2.has_key(d1[x])]) #.keys() is optional, cf notes
>>> d3
{'a': 'male', 'd': 'faucet'}
В двух словах, строка с d3 =
говорит следующее:
d3 is a new dict object made from
all the pairs
made of x, the key of d1 and d2[d1[x]]
(above are respectively the "a"s and the "c"s in the problem)
where x is taken from all the keys of d1 (the "a"s in the problem)
if d2 has indeed a key equal to d1[x]
(above condition avoids the key errors when getting d2[d1[x]])