def index_tensor_in(tensor, l, raise_error=True):
    """Find the index in list.

    Args:
        tensor: tensor to find.
        l: An iterable object.
        raise_error: If `True`, raise error if tensor is not in the list,
            otherwise return `None`.
    """
    for i, val in enumerate(l):
        if id(tensor) == id(val):
            return i
    if raise_error:
        raise ValueError('Tensor not in list')
    else:
        return None