# cycler.Cycler

class cycler.Cycler(left: Cycler[K, V] | Iterable[dict[K, V]] | None, right: Cycler[K, V] | None = None, op: Any = None)

  Composable cycles.

  This class has compositions methods:

  `+`

    for ‘inner’ products (zip)

  `+=`

    in-place `+`

  `*`

    for outer products (`itertools.product`) and integer multiplication

  `*=`

    in-place `*`

  and supports basic slicing via `[]`.

  Parameters:
    left, right Cycler or None

      The ‘left’ and ‘right’ cyclers.

    op func or None

      Function which composes the ‘left’ and ‘right’ cyclers.

  __init__(left: Cycler[K, V] | Iterable[dict[K, V]] | None, right: Cycler[K, V] | None = None, op: Any = None)

    Semi-private init.

    Do not use this directly, use `cycler` function instead.

  Methods

  `__init__`(left[, right, op]) | Semi-private init.
  `by_key`() | Values by key.
  `change_key`(old, new) | Change a key in this cycler to a new name.
  `concat`(right) | Concatenate `Cycler`s, as if chained using `itertools.chain`.
  `simplify`() | Simplify the cycler into a sum (but no products) of cyclers.

  Attributes

  `keys` | The keys this Cycler knows about.

  by_key() → dict[K, list[V]]

    Values by key.

    This returns the transposed values of the cycler. Iterating over a `Cycler` yields dicts with a single value for each key, this method returns a `dict` of `list` which are the values for the given key.

    The returned value can be used to create an equivalent `Cycler` using only `+`.

    Returns:
      transpose dict

        dict of lists of the values for each key.

  change_key(old: K, new: K) → None

    Change a key in this cycler to a new name. Modification is performed in-place.

    Does nothing if the old key is the same as the new key. Raises a ValueError if the new key is already a key. Raises a KeyError if the old key isn’t a key.

  concat(right: Cycler[K, U]) → Cycler[K, V | U]

    Concatenate `Cycler`s, as if chained using `itertools.chain`.

    The keys must match exactly.

    Returns:
      `Cycler`

        The concatenated cycler.

    Examples

        >>> num = cycler('a', range(3))
        >>> let = cycler('a', 'abc')
        >>> num.concat(let)
        cycler('a', [0, 1, 2, 'a', 'b', 'c'])

  property keys: set[K]

    The keys this Cycler knows about.

  simplify() → Cycler[K, V]

    Simplify the cycler into a sum (but no products) of cyclers.

    Returns:
      simple Cycler