def get_training_or_validation_split(samples, labels, validation_split, subset):
    """Potentially restrict samples & labels to a training or validation split.

    Args:
        samples: List of elements.
        labels: List of corresponding labels.
        validation_split: Float, fraction of data to reserve for validation.
        subset: Subset of the data to return.
            Either `"training"`, `"validation"`, or `None`.
            If `None`, we return all of the data.

    Returns:
        tuple (samples, labels), potentially restricted to the specified subset.
    """
    if not validation_split:
        return samples, labels

    num_val_samples = int(validation_split * len(samples))
    if subset == "training":
        io_utils.print_msg(
            f"Using {len(samples) - num_val_samples} files for training."
        )
        samples = samples[:-num_val_samples]
        if labels is not None:
            labels = labels[:-num_val_samples]
    elif subset == "validation":
        io_utils.print_msg(f"Using {num_val_samples} files for validation.")
        samples = samples[-num_val_samples:]
        if labels is not None:
            labels = labels[-num_val_samples:]
    else:
        raise ValueError(
            '`subset` must be either "training" '
            f'or "validation", received: {subset}'
        )
    return samples, labels
Potentially restrict samples & labels to a training or validation split.

    Args:
        samples: List of elements.
        labels: List of corresponding labels.
        validation_split: Float, fraction of data to reserve for validation.
        subset: Subset of the data to return.
            Either `"training"`, `"validation"`, or `None`.
            If `None`, we return all of the data.

    Returns:
        tuple (samples, labels), potentially restricted to the specified subset.
    
keras/src/utils/dataset_utils.py