Enumerator

digraph InheritanceGraph { graph [bgcolor=transparent, color=lightsteelblue2, fontname=Arial, fontsize=10, outputorder=edgesfirst, overlap=prism, penwidth=2, rankdir=LR, splines=spline, style="dashed, rounded", truecolor=true]; node [colorscheme=pastel19, fontname=Arial, fontsize=10, height=0, penwidth=2, shape=box, style="filled, rounded", width=0]; edge [color=lightslategrey, penwidth=1]; subgraph "cluster_abjad.system" { graph [label="abjad.system"]; node [color=1]; "abjad.system.AbjadObject.AbjadObject" [URL="../api/abjad/utilities/../system/AbjadObject.html#abjad.system.AbjadObject.AbjadObject", label="Abjad\nObject", target=_top]; "abjad.system.AbjadValueObject.AbjadValueObject" [URL="../api/abjad/utilities/../system/AbjadValueObject.html#abjad.system.AbjadValueObject.AbjadValueObject", label="Abjad\nValue\nObject", target=_top]; "abjad.system.AbjadObject.AbjadObject" -> "abjad.system.AbjadValueObject.AbjadValueObject"; } subgraph "cluster_abjad.utilities" { graph [label="abjad.utilities"]; node [color=2]; "abjad.utilities.Enumerator.Enumerator" [URL="../api/abjad/utilities/Enumerator.html#abjad.utilities.Enumerator.Enumerator", color=black, fontcolor=white, label=Enumerator, target=_top]; } subgraph cluster_builtins { graph [label=builtins]; node [color=3]; "builtins.object" [URL="https://docs.python.org/3.6/library/functions.html#object", label=object, target=_top]; } "abjad.system.AbjadValueObject.AbjadValueObject" -> "abjad.utilities.Enumerator.Enumerator"; "builtins.object" -> "abjad.system.AbjadObject.AbjadObject"; }

class abjad.utilities.Enumerator.Enumerator(sequence=None)

Enumerator.

Collects combinatorial enumerator methods.


Attributes Summary

sequence Gets sequence of enumerator.
yield_combinations Yields combinations of sequence items.
yield_outer_product Yields outer product of sequences in sequence.
yield_pairs Yields pairs sequence items.
yield_partitions Yields partitions of sequence.
yield_permutations Yields permutations of sequence.
yield_set_partitions Yields set partitions of sequence.
yield_subsequences Yields subsequences of sequence.

Special methods

(AbjadValueObject).__copy__(*arguments)

Copies Abjad value object.

Returns new Abjad value object.

(AbjadValueObject).__eq__(argument)

Is true when all initialization values of Abjad value object equal the initialization values of argument.

Returns true or false.

(AbjadObject).__format__(format_specification='')

Formats Abjad object.

Set format_specification to '' or 'storage'. Interprets '' equal to 'storage'.

Returns string.

(AbjadValueObject).__hash__()

Hashes Abjad value object.

Returns integer.

(AbjadObject).__repr__()

Gets interpreter representation of Abjad object.

Returns string.


Methods

yield_combinations(minimum_length=None, maximum_length=None)

Yields combinations of sequence items.

>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations():
...     combination
Sequence([])
Sequence([1])
Sequence([2])
Sequence([1, 2])
Sequence([3])
Sequence([1, 3])
Sequence([2, 3])
Sequence([1, 2, 3])
Sequence([4])
Sequence([1, 4])
Sequence([2, 4])
Sequence([1, 2, 4])
Sequence([3, 4])
Sequence([1, 3, 4])
Sequence([2, 3, 4])
Sequence([1, 2, 3, 4])
>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations(
...     minimum_length=3,
...     ):
...     combination
Sequence([1, 2, 3])
Sequence([1, 2, 4])
Sequence([1, 3, 4])
Sequence([2, 3, 4])
Sequence([1, 2, 3, 4])
>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations(
...     maximum_length=2,
...     ):
...     combination
Sequence([])
Sequence([1])
Sequence([2])
Sequence([1, 2])
Sequence([3])
Sequence([1, 3])
Sequence([2, 3])
Sequence([4])
Sequence([1, 4])
Sequence([2, 4])
Sequence([3, 4])
>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for combination in enumerator.yield_combinations(
...     minimum_length=2,
...     maximum_length=2,
...     ):
...     combination
Sequence([1, 2])
Sequence([1, 3])
Sequence([2, 3])
Sequence([1, 4])
Sequence([2, 4])
Sequence([3, 4])
>>> enumerator = abjad.Enumerator('text')
>>> for combination in enumerator.yield_combinations():
...     ''.join([str(_) for _ in combination])
''
't'
'e'
'te'
'x'
'tx'
'ex'
'tex'
't'
'tt'
'et'
'tet'
'xt'
'txt'
'ext'
'text'

Yields combinations in binary string order.

Returns sequence generator.

yield_outer_product()

Yields outer product of sequences in sequence.

>>> sequences = [[1, 2, 3], ['a', 'b']]
>>> enumerator = abjad.Enumerator(sequences)
>>> for sequence_ in enumerator.yield_outer_product():
...     sequence_
...
Sequence([1, 'a'])
Sequence([1, 'b'])
Sequence([2, 'a'])
Sequence([2, 'b'])
Sequence([3, 'a'])
Sequence([3, 'b'])
>>> sequences = [[1, 2, 3], ['a', 'b'], ['X', 'Y']]
>>> enumerator = abjad.Enumerator(sequences)
>>> for sequence_ in enumerator.yield_outer_product():
...     sequence_
...
Sequence([1, 'a', 'X'])
Sequence([1, 'a', 'Y'])
Sequence([1, 'b', 'X'])
Sequence([1, 'b', 'Y'])
Sequence([2, 'a', 'X'])
Sequence([2, 'a', 'Y'])
Sequence([2, 'b', 'X'])
Sequence([2, 'b', 'Y'])
Sequence([3, 'a', 'X'])
Sequence([3, 'a', 'Y'])
Sequence([3, 'b', 'X'])
Sequence([3, 'b', 'Y'])
>>> sequences = [[1, 2, 3], [4, 5], [6, 7, 8]]
>>> enumerator = abjad.Enumerator(sequences)
>>> for sequence_ in enumerator.yield_outer_product():
...     sequence_
...
Sequence([1, 4, 6])
Sequence([1, 4, 7])
Sequence([1, 4, 8])
Sequence([1, 5, 6])
Sequence([1, 5, 7])
Sequence([1, 5, 8])
Sequence([2, 4, 6])
Sequence([2, 4, 7])
Sequence([2, 4, 8])
Sequence([2, 5, 6])
Sequence([2, 5, 7])
Sequence([2, 5, 8])
Sequence([3, 4, 6])
Sequence([3, 4, 7])
Sequence([3, 4, 8])
Sequence([3, 5, 6])
Sequence([3, 5, 7])
Sequence([3, 5, 8])

Returns sequence generator.

yield_pairs()

Yields pairs sequence items.

Without duplicate items:

>>> enumerator = abjad.Enumerator([1, 2, 3, 4])
>>> for pair in enumerator.yield_pairs():
...     pair
...
Sequence([1, 2])
Sequence([1, 3])
Sequence([1, 4])
Sequence([2, 3])
Sequence([2, 4])
Sequence([3, 4])

With duplicate items:

>>> enumerator = abjad.Enumerator([1, 1, 1])
>>> for pair in enumerator.yield_pairs():
...     pair
...
Sequence([1, 1])
Sequence([1, 1])
Sequence([1, 1])

Length-1 sequence:

>>> enumerator = abjad.Enumerator([1])
>>> for pair in enumerator.yield_pairs():
...     pair
...

Empty sequence:

>>> enumerator = abjad.Enumerator([])
>>> for pair in enumerator.yield_pairs():
...     pair
...

Returns generator of length-2 sequences.

yield_partitions()

Yields partitions of sequence.

>>> enumerator = abjad.Enumerator([0, 1, 2])
>>> for partition in enumerator.yield_partitions():
...     partition
...
Sequence([Sequence([0, 1, 2])])
Sequence([Sequence([0, 1]), Sequence([2])])
Sequence([Sequence([0]), Sequence([1, 2])])
Sequence([Sequence([0]), Sequence([1]), Sequence([2])])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3])
>>> for partition in enumerator.yield_partitions():
...     partition
...
Sequence([Sequence([0, 1, 2, 3])])
Sequence([Sequence([0, 1, 2]), Sequence([3])])
Sequence([Sequence([0, 1]), Sequence([2, 3])])
Sequence([Sequence([0, 1]), Sequence([2]), Sequence([3])])
Sequence([Sequence([0]), Sequence([1, 2, 3])])
Sequence([Sequence([0]), Sequence([1, 2]), Sequence([3])])
Sequence([Sequence([0]), Sequence([1]), Sequence([2, 3])])
Sequence([Sequence([0]), Sequence([1]), Sequence([2]), Sequence([3])])

Returns generator of nested sequences.

yield_permutations()

Yields permutations of sequence.

>>> enumerator = abjad.Enumerator([1, 2, 3])
>>> for permutation in enumerator.yield_permutations():
...     permutation
...
Sequence([1, 2, 3])
Sequence([1, 3, 2])
Sequence([2, 1, 3])
Sequence([2, 3, 1])
Sequence([3, 1, 2])
Sequence([3, 2, 1])

Returns sequence generator.

yield_set_partitions()

Yields set partitions of sequence.

>>> enumerator = abjad.Enumerator([21, 22, 23, 24])
>>> for set_partition in enumerator.yield_set_partitions():
...     set_partition
...
Sequence([Sequence([21, 22, 23, 24])])
Sequence([Sequence([21, 22, 23]), Sequence([24])])
Sequence([Sequence([21, 22, 24]), Sequence([23])])
Sequence([Sequence([21, 22]), Sequence([23, 24])])
Sequence([Sequence([21, 22]), Sequence([23]), Sequence([24])])
Sequence([Sequence([21, 23, 24]), Sequence([22])])
Sequence([Sequence([21, 23]), Sequence([22, 24])])
Sequence([Sequence([21, 23]), Sequence([22]), Sequence([24])])
Sequence([Sequence([21, 24]), Sequence([22, 23])])
Sequence([Sequence([21]), Sequence([22, 23, 24])])
Sequence([Sequence([21]), Sequence([22, 23]), Sequence([24])])
Sequence([Sequence([21, 24]), Sequence([22]), Sequence([23])])
Sequence([Sequence([21]), Sequence([22, 24]), Sequence([23])])
Sequence([Sequence([21]), Sequence([22]), Sequence([23, 24])])
Sequence([Sequence([21]), Sequence([22]), Sequence([23]), Sequence([24])])

Returns set partitions in order of restricted growth function.

Returns generator of list of lists.

yield_subsequences(minimum_length=0, maximum_length=None)

Yields subsequences of sequence.

>>> enumerator = abjad.Enumerator([0, 1, 2])
>>> for subsequence in enumerator.yield_subsequences():
...     subsequence
...
Sequence([])
Sequence([0])
Sequence([0, 1])
Sequence([0, 1, 2])
Sequence([1])
Sequence([1, 2])
Sequence([2])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3, 4])
>>> for subsequence in enumerator.yield_subsequences(
...     minimum_length=3,
...     ):
...     subsequence
...
Sequence([0, 1, 2])
Sequence([0, 1, 2, 3])
Sequence([0, 1, 2, 3, 4])
Sequence([1, 2, 3])
Sequence([1, 2, 3, 4])
Sequence([2, 3, 4])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3, 4])
>>> for subsequence in enumerator.yield_subsequences(
...     maximum_length=3,
...     ):
...     subsequence
...
Sequence([])
Sequence([0])
Sequence([0, 1])
Sequence([0, 1, 2])
Sequence([1])
Sequence([1, 2])
Sequence([1, 2, 3])
Sequence([2])
Sequence([2, 3])
Sequence([2, 3, 4])
Sequence([3])
Sequence([3, 4])
Sequence([4])
>>> enumerator = abjad.Enumerator([0, 1, 2, 3, 4])
>>> for subsequence in enumerator.yield_subsequences(
...     minimum_length=3,
...     maximum_length=3,
...     ):
...     subsequence
...
Sequence([0, 1, 2])
Sequence([1, 2, 3])
Sequence([2, 3, 4])

Returns sequence generator.


Read-only properties

sequence

Gets sequence of enumerator.

Defaults to none.

Set to sequence or none.

Returns sequence or none.