Last active
April 25, 2017 08:33
-
-
Save nooperpudd/55be591ddfb1e9af78c49e80a12b279b to your computer and use it in GitHub Desktop.
Check dict list common keys
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_common_keys(dict_list): | |
""" | |
check python dict list common keys | |
:param dict_list: [{},{}...] | |
:return: | |
""" | |
if len(dict_list) >= 2: | |
common_keys = set(dict_list[0].keys()) | |
for dict_item in dict_list[1:]: | |
common_keys.intersection_update(set(dict_item.keys())) | |
return common_keys | |
a={"a":"b","c":"d"} | |
b={"c":"e","f":"g","a":"dd"} | |
c={"a":"f","c":"cc"} | |
check_dict_conflict([a,b,c]) | |
# output: {'a', 'c'} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment