def lookup_named_tensor(name, named_tensors):
    """Retrieves a NamedTensor by name.

    Args:
      name: Name of the tensor to retrieve.
      named_tensors: List of NamedTensor objects to search.

    Returns:
      The NamedTensor in |named_tensors| with the |name|.

    Raises:
      KeyError: If the |name| is not found among the |named_tensors|.
    """
    for named_tensor in named_tensors:
        if named_tensor.name == name:
            return named_tensor
    raise KeyError('Name "%s" not found in named tensors: %s' % (name,
                                                                 named_tensors))