I have two dictionaries
a = {'home': {'name': 'Team1', 'score': 0}, 'away': {'name': 'Team2', 'score': 0}}
b = {'home': {'name': 'Team1', 'score': 2}, 'away': {'name': 'Team2', 'score': 0}}
The keys never change but I want to get that ['home']['score'] has changed
Any easy way to do this?
As a knee-jerk initial response:
a = {'home': {'name': 'Team1', 'score': 0}, 'away': {'name': 'Team2', 'score': 0}}
b = {'home': {'name': 'Team1', 'score': 2}, 'away': {'name': 'Team2', 'score': 0}}def valchange(d1, d2, parent=''):changes=[]for k in d1.keys():if type(d1[k])==type({}):changes.extend(valchange(d1[k], d2[k], k))else:if d1[k]!=d2[k]:if parent=='':changes.append(k + ' has changed ')else:changes.append(parent + '.' + k + ' has changed')return changesprint valchange(a,b)>>>
['home.score has changed']