I have multiple dictionaries and a base dictionary. I need to iterate through the dictionaries keys and need to check the existing keys and new keys in each iteration but in each iteration, I need to combine all previous keys of dictionary and check with current dictionary key for example
dict10 = {'A':1, 'C':2} #base dictionary
dict11 = {'B':3, 'C':4}
dict12 = {'A':5, 'E':6, 'F':7}
here is the calculation process
Exist_Score = (values of keys in dict11.keys() & dict10.keys()) + (values of keys in dict12.keys() & (dict11.keys() + dict10.keys()))
New_score = (values of keys in dict11.keys() - dict10.keys()) + (values of keys in dict12.keys() - (dict11.keys() + dict10.keys()))
my manual way to calculate the scores
exist_score = 0
new_score = 0
for key in dict11.keys() & dict10.keys():
exist_score += dict11[key]
for key in dict12.keys() & set(dict11.keys()).union(set(dict10.keys())):
exist_score += dict12[key]
for key in dict11.keys() - dict10.keys():
new_score += dict11[key]
for key in dict12.keys() - set(dict11.keys()).union(set(dict10.keys())):
new_score += dict12[key]
print(exist_score)
print(new_score)
for the given example the score will
Exist_Score = 4 + 5
New_Score = 3 + (6 + 7)
How can I achieve this for a dynamic number of lists and iteratively combine lists to check the keys?