def merge_dicts(dict1, dict2, append_lists=False):
 for key in dict2:
  if isinstance(dict2[key], dict):
   if ((key in dict1) and (key in dict2)):
    merge_dicts(dict1[key], dict2[key])
   else:
    dict1[key] = dict2[key]
  elif (isinstance(dict2[key], list) and append_lists):
   if ((key in dict1) and isinstance(dict1[key], list)):
    dict1[key].extend(dict2[key])
   else:
    dict1[key] = dict2[key]
  else:
   dict1[key] = dict2[key]

def merge_dicts ( dict1 , dict2 , append_lists = False ) : for key in dict2 : if isinstance ( dict2 [ key ] , dict ) : if ( ( key in dict1 ) and ( key in dict2 ) ) : merge_dicts ( dict1 [ key ] , dict2 [ key ] ) else : dict1 [ key ] = dict2 [ key ] elif ( isinstance ( dict2 [ key ] , list ) and append_lists ) : if ( ( key in dict1 ) and isinstance ( dict1 [ key ] , list ) ) : dict1 [ key ] . extend ( dict2 [ key ] ) else : dict1 [ key ] = dict2 [ key ] else : dict1 [ key ] = dict2 [ key ]
merge b into a recursively .