def flatten_dict(data, flattened=None, old_key=None):
 flattened = (flattened or {})
 old_key = (old_key or [])
 for (key, value) in data.iteritems():
  new_key = (old_key + [key])
  if (isinstance(value, list) and value and isinstance(value[0], dict)):
   flattened = flatten_list(value, flattened, new_key)
  else:
   flattened[tuple(new_key)] = value
 return flattened

def flatten_dict ( data , flattened = None , old_key = None ) : flattened = ( flattened or { } ) old_key = ( old_key or [ ] ) for ( key , value ) in data . iteritems ( ) : new_key = ( old_key + [ key ] ) if ( isinstance ( value , list ) and value and isinstance ( value [ 0 ] , dict ) ) : flattened = flatten_list ( value , flattened , new_key ) else : flattened [ tuple ( new_key ) ] = value return flattened
flatten a dict .