Created
February 13, 2016 07:07
-
-
Save knowshan/63042417d6c1e52c0329 to your computer and use it in GitHub Desktop.
Common items in simple dictionary structure
This file contains hidden or 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
#!/usr/bin/env python | |
dict_1 = {'apple': 'red', 'banana': 'yellow', 'guava': 'green', 'orange': 'orange'} | |
dict_2 = {'apple': 'red', 'banana': 'yellow', 'grapes': 'green', 'orange': 'orange', 'guava': 'red',} | |
# Nested list comps to get keys of common dict items | |
ks = [i for i in [k for k in dict_1 if k in dict_2] if dict_1[i] == dict_2[i] ] | |
for k in ks: | |
print k, dict_1[k] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment