def diff_dicts(d, expected, prefix=None):
 prefix = (prefix or [])
 diffs = {}
 for k in set((d.keys() + expected.keys())):
  current_prefix = (prefix + [k])
  want = d.get(k)
  got = expected.get(k)
  if (isinstance(want, dict) and isinstance(got, dict)):
   diffs.update(diff_dicts(got, want, prefix=current_prefix))
  elif (got != want):
   key = '.'.join(current_prefix)
   diffs[key] = (got, want)
 return diffs

def diff_dicts ( d , expected , prefix = None ) : prefix = ( prefix or [ ] ) diffs = { } for k in set ( ( d . keys ( ) + expected . keys ( ) ) ) : current_prefix = ( prefix + [ k ] ) want = d . get ( k ) got = expected . get ( k ) if ( isinstance ( want , dict ) and isinstance ( got , dict ) ) : diffs . update ( diff_dicts ( got , want , prefix = current_prefix ) ) elif ( got != want ) : key = '.' . join ( current_prefix ) diffs [ key ] = ( got , want ) return diffs
given 2 dicts .