def _find_formatter(formatters):
  """Returns a formatter that takes x, and applies formatter based on types.

  Args:
    formatters: map from type to formatter

  Returns:
    function: x -> displayable output
  """

  def formatter(x):
    for type_, formatter_for_type in formatters.items():
      if isinstance(x, type_):
        return formatter_for_type(x)
    return x

  return formatter