import six


def flatten_dict(original_dict, delimiter="/"):
  """Flattens a dictionary of dictionaries by one level.

  Note that top level keys will be overridden if they collide with flat keys.
  E.g. using delimiter="/" and origial_dict={"foo/bar": 1, "foo": {"bar": 2}},
  the top level "foo/bar" key would be overwritten.

  Args:
    original_dict: The dictionary to flatten.
    delimiter: The value used to delimit the keys in the flat_dict.

  Returns:
    The falttened dictionary.
  """

  flat_dict = {}
  for outer_key, inner_dict in six.iteritems(original_dict):
    if isinstance(inner_dict, dict):
      for inner_key, value in six.iteritems(inner_dict):
        flat_dict["{}{}{}".format(outer_key, delimiter, inner_key)] = value
    else:
      flat_dict[outer_key] = inner_dict
  return flat_dict