Skip to content

Instantly share code, notes, and snippets.

@embayer
Created December 8, 2015 20:39
Show Gist options
  • Save embayer/b475929492c1f04186ae to your computer and use it in GitHub Desktop.
Save embayer/b475929492c1f04186ae to your computer and use it in GitHub Desktop.
check if a_list already contains a_dict
from json import dumps
def dict_in_list(a_dict, a_list):
"""
check if a_list already contains a_dict
"""
def dict_equals_dict(dict_a, dict_b):
"""
check if all key-value-pairs of dict_a and dict_b are equal
"""
return True if dumps(dict_b, sort_keys=True) is dumps(dict_b, sort_keys=True) else False
return True if any(dict_equals_dict(a_dict, list_dict) for list_dict in a_list) else False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment