Skip to content

Instantly share code, notes, and snippets.

@jacqueswww
Created May 25, 2016 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jacqueswww/e8116aedf05a3b19355c46265e687f0f to your computer and use it in GitHub Desktop.
Save jacqueswww/e8116aedf05a3b19355c46265e687f0f to your computer and use it in GitHub Desktop.
One dictionary exists in another
def dict_contains(primary, secondary):
"""
Does primary dict contains all the same items as secondary.
"""
assert isinstance(primary, dict)
assert isinstance(secondary, dict)
for key, val in secondary.items():
if key not in primary:
return False
elif primary[key] != val:
return False
return True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment