Skip to content

Instantly share code, notes, and snippets.

@nooperpudd
Last active August 23, 2017 06:17
Show Gist options
  • Save nooperpudd/d0e3dd897b75a821e7a21823a5fd6113 to your computer and use it in GitHub Desktop.
Save nooperpudd/d0e3dd897b75a821e7a21823a5fd6113 to your computer and use it in GitHub Desktop.
dict common keys
def check_dict_common_keys(dict_list):
"""
check the dict common keys in the dict list
:param dict_list: [{},{}...]
:return: set()
"""
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment