Created
April 10, 2015 14:07
-
-
Save Averroes/8beca5742f186290d8d5 to your computer and use it in GitHub Desktop.
finding out what two dictionaries have in common
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# example.py | |
# | |
# Find out what two dictionaries have in common | |
a = { | |
'x' : 1, | |
'y' : 2, | |
'z' : 3 | |
} | |
b = { | |
'w' : 10, | |
'x' : 11, | |
'y' : 2 | |
} | |
print('Common keys:', a.keys() & b.keys()) | |
print('Keys in a not in b:', a.keys() - b.keys()) | |
print('(key,value) pairs in common:', a.items() & b.items()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment