Skip to content

Choice

Bases: Collection[T]

A list of values to choose from in a hyperparameter search.

Source code in src/safeds/ml/hyperparameters/_choice.py
class Choice(Collection[T]):
    """A list of values to choose from in a hyperparameter search."""

    def __init__(self, *args: T) -> None:
        """
        Create a new choice.

        Parameters
        ----------
        *args:
            The values to choose from.
        """
        self.elements = list(args)

    def __contains__(self, value: Any) -> bool:
        """
        Check if a value is in this choice.

        Parameters
        ----------
        value:
            The value to check.

        Returns
        -------
        is_in_choice:
            Whether the value is in this choice.
        """
        return value in self.elements

    def __iter__(self) -> Iterator[T]:
        """
        Iterate over the values of this choice.

        Returns
        -------
        iterator:
            An iterator over the values of this choice.
        """
        return iter(self.elements)

    def __len__(self) -> int:
        """
        Get the number of values in this choice.

        Returns
        -------
        number_of_values:
            The number of values in this choice.
        """
        return len(self.elements)

elements = list(args)