def METHOD_NAME(batch: Any, key: Union[int, str], value: Any) -> Any:
    """Sets key value pairs in tuples and NamedTuples."""
    if hasattr(batch, '_fields'):  # NamedTuple
        if isinstance(key, str):
            batch = batch._replace(**{key: value})
        else:
            batch_list = list(batch)
            batch_list[key] = value
            batch = batch._make(batch_list)
    else:  # Normal tuple.
        batch = list(batch)
        batch[key] = value
        batch = tuple(batch)
    return batch