def _key_splitting(rect_dict, keys, values, key_subset, horizontal, gap):
 result = OrderedDict()
 L = len(key_subset)
 for (name, (x, y, w, h)) in iteritems(rect_dict):
  if (key_subset == name[:L]):
   divisions = _split_rect(x, y, w, h, values, horizontal, gap)
   for (key, rect) in zip(keys, divisions):
    result[(name + (key,))] = rect
  else:
   result[name] = (x, y, w, h)
 return result

def _key_splitting ( rect_dict , keys , values , key_subset , horizontal , gap ) : result = OrderedDict ( ) L = len ( key_subset ) for ( name , ( x , y , w , h ) ) in iteritems ( rect_dict ) : if ( key_subset == name [ : L ] ) : divisions = _split_rect ( x , y , w , h , values , horizontal , gap ) for ( key , rect ) in zip ( keys , divisions ) : result [ ( name + ( key , ) ) ] = rect else : result [ name ] = ( x , y , w , h ) return result
given a dictionary where each entry is a rectangle .