0
I have 2 dictionaries for example:
dict = {1 : a, 2 : b, 3 : c, 4 : d}
dict1= {5 : z, 1 : y, 6 : x, 3 : u}
I need to compare the keys of 2 dictionaries and if they are equal, I have to print the corresponding value of the 2nd dictionary's key. For example, both dictionaries have 1 and 3 as their key so I have to print their corresponding value in the 2nd dictionary i.e. it should print y
and u
. How to write the python script for this? I have tried something like:
def compare(dictOne,dictTwo):
for keyOne in dictOne:
for keyTwo in dictTwo:
if keyOne == keyTwo:
print(dictTwo[keyTwo])
But I am not getting the output.
1While this may answer the question, it would be a better answer if you could provide some explanation why it does so. – DavidPostill – 2015-11-25T21:16:14.800