Skip to content

Instantly share code, notes, and snippets.

@Averroes
Created April 10, 2015 14:07
Show Gist options
  • Save Averroes/8beca5742f186290d8d5 to your computer and use it in GitHub Desktop.
Save Averroes/8beca5742f186290d8d5 to your computer and use it in GitHub Desktop.
finding out what two dictionaries have in common
# 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