Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. def dict_common_keys(dict_list):
  2. """
  3. check python dict list common keys
  4. :param dict_list: [{},{}...]
  5. :return:
  6. """
  7. if len(dict_list) >= 2:
  8. common_keys = set(dict_list[0].keys())
  9. for dict_item in dict_list[1:]:
  10. common_keys.intersection_update(set(dict_item.keys()))
  11. return common_keys
  12.  
  13. a={"a":"b","c":"d"}
  14. b={"c":"e","f":"g","a":"dd"}
  15. c={"a":"f","c":"cc"}
  16.  
  17. check_dict_conflict([a,b,c])
  18. # output: {'a', 'c'}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement