Created
July 15, 2016 09:31
-
-
Save jdsingh/04c6f21b1b10515ed45511cd764a467a to your computer and use it in GitHub Desktop.
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
def dict_interdiff(d1, d2): | |
''' | |
d1, d2: dicts whose keys and values are integers | |
Returns a tuple of dictionaries according to the instructions above | |
''' | |
intersect = {} | |
difference = {} | |
for key in d1.keys(): | |
if d2.has_key(key): | |
# add common keys | |
intersect[key] = f(d1.get(key), d2.get(key)) | |
else: | |
# add keys of d1 that does not appear in d2 | |
difference[key] = d1.get(key) | |
for key in d2.keys(): | |
if not d1.has_key(key): | |
# add keys of d2 that does not appear in d1 | |
difference[key] = d2.get(key) | |
return (intersect, difference) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment