def _format_like_example(args, example, key_order):
  """Returns args as instance, ordered list or dict, following `example` format.

  Note: facilitates single, multi-output or named multi-output Keras model API.

  Args:
    args: ordered tuple of arguments.
    example: example of format to follow: single instance, tuple or dict.
    key_order: keys for arguments in case `example` of type dict.

  Returns:
    args formatted as `example`.
  """
  if isinstance(example, dict):
    result = dict(zip(key_order, args))
  elif isinstance(example, (tuple, list)) and not len(example):  # pylint: disable=g-explicit-length-test
    # Empty single instance.
    result = []
  elif (isinstance(example, (tuple, list)) and
        isinstance(example[0], (tuple, list))):
    result = args
  else:
    result = args[0]
  return result