class cycler.Cycler(left, right=None, op=None)[source]

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 []


left : Cycler or None

The ‘left’ cycler

right : Cycler or None

The ‘right’ cycler

op : func or None

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

__init__(left, right=None, op=None)[source]

Semi-private init

Do not use this directly, use cycler function instead.


__init__(left[, right, op]) Semi-private init
change_key(old, new) Change a key in this cycler to a new name.
concat(other) Concatenate this cycler and an other.
simplify() Simplify the Cycler


keys The keys this Cycler knows about

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 +.


transpose : dict

dict of lists of the values for each key.

change_key(old, new)[source]

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.


Concatenate this cycler and an other.

The keys must match exactly.

This returns a single Cycler which is equivalent to itertools.chain(self, other)


other : Cycler

The Cycler to concatenate to this one.


ret : Cycler

The concatenated Cycler


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

The keys this Cycler knows about


Simplify the Cycler

Returned as a composition using only sums (no multiplications)


simple : Cycler

An equivalent cycler using only summation