def compare_dict(x, y):
shared_items = {k: x[k] for k in x if k in y and x[k] == y[k]}
differing_values = {k: x[k] for k in x if k in y and x[k] != y[k]}
differing_keys = [k for k in x if k not in y]
return {
"shared_items_in_x": shared_items,
"differing_values_in_x": differing_values,
"differing_keys_in_x": differing_keys
}
def is_dict_in_list(d, l):
rtn = False
for k in l:
cd = compare_dict(d, k)
if(len(cd['differing_values_in_x']) == 0 and len(cd['differing_keys_in_x']) == 0):
rtn = True
break
return rtn
def purify_list_of_dicts(inlist):
nlist = [i for j in inlist for i in j]
olist = []
for i in range(0, len(nlist)):
if is_dict_in_list(nlist[i], olist) == False:
olist.append(nlist[i])
return olist
Pages
- Index of Lessons in Technology
- Index of Book Summaries
- Index of Book Lists And Downloads
- Index For Job Interviews Preparation
- Index of "Algorithms: Design and Analysis"
- Python Course (Index)
- Data Analytics Course (Index)
- Index of Machine Learning
- Postings Index
- Index of BITS WILP Exam Papers and Content
- Lessons in Investing
- Index of Math Lessons
- Downloads
- Index of Management Lessons
- Book Requests
- Index of English Lessons
- Index of Medicines
- Index of Quizzes (Educational)
Tuesday, August 23, 2022
Compare two dictionaries in Python
Labels:
Python
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment