I have a list of dictionaries and need to iterate through them and check for the keys that exist already. I have implemented a python code to manually calculate a score as below. In my code, I'm manually combining keys from previous dictionaries in each iteration. Iteration will start from dict11.
How can I change this code to automatically iterate through a dynamic number of dictionaries and in each iteration how can I combine the keys dynamically?
dict10 = {'A': 1, 'C': 2}
dict11 = {'B': 3, 'C': 4}
dict12 = {'A': 5, 'E': 6, 'F': 7}
dict13 = {'G': 8, 'E': 9}
exist_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 dict13.keys() & set(dict12.keys()).union(set(dict11.keys()).union(set(dict10.keys()))):
exist_score += dict13[key]
print(exist_score)