Created
December 8, 2015 20:39
-
-
Save embayer/b475929492c1f04186ae to your computer and use it in GitHub Desktop.
check if a_list already contains a_dict
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
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