enumerate


Functions

outer_product

Yields outer product of sequences in argument.

yield_combinations

Yields combinations of sequence items.

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.

abjad.enumerate.outer_product(argument)[source]

Yields outer product of sequences in argument.

>>> sequences = [list([1, 2, 3]), list(["a", "b"])]
>>> for sequence in abjad.enumerate.outer_product(sequences):
...     sequence
... 
[1, 'a']
[1, 'b']
[2, 'a']
[2, 'b']
[3, 'a']
[3, 'b']
>>> sequences = [[1, 2, 3], ["a", "b"], ["X", "Y"]]
>>> for sequence in abjad.enumerate.outer_product(sequences):
...     sequence
... 
[1, 'a', 'X']
[1, 'a', 'Y']
[1, 'b', 'X']
[1, 'b', 'Y']
[2, 'a', 'X']
[2, 'a', 'Y']
[2, 'b', 'X']
[2, 'b', 'Y']
[3, 'a', 'X']
[3, 'a', 'Y']
[3, 'b', 'X']
[3, 'b', 'Y']
>>> sequences = [[1, 2, 3], [4, 5], [6, 7, 8]]
>>> for sequence in abjad.enumerate.outer_product(sequences):
...     sequence
... 
[1, 4, 6]
[1, 4, 7]
[1, 4, 8]
[1, 5, 6]
[1, 5, 7]
[1, 5, 8]
[2, 4, 6]
[2, 4, 7]
[2, 4, 8]
[2, 5, 6]
[2, 5, 7]
[2, 5, 8]
[3, 4, 6]
[3, 4, 7]
[3, 4, 8]
[3, 5, 6]
[3, 5, 7]
[3, 5, 8]

Returns list of lists.

abjad.enumerate.yield_combinations(argument, minimum_length=None, maximum_length=None)[source]

Yields combinations of sequence items.

>>> sequence = list([1, 2, 3, 4])
>>> for combination in abjad.enumerate.yield_combinations(sequence):
...     combination
... 
[]
[1]
[2]
[1, 2]
[3]
[1, 3]
[2, 3]
[1, 2, 3]
[4]
[1, 4]
[2, 4]
[1, 2, 4]
[3, 4]
[1, 3, 4]
[2, 3, 4]
[1, 2, 3, 4]
>>> sequence = list([1, 2, 3, 4])
>>> for combination in abjad.enumerate.yield_combinations(
...     sequence,
...     minimum_length=3,
... ):
...     combination
... 
[1, 2, 3]
[1, 2, 4]
[1, 3, 4]
[2, 3, 4]
[1, 2, 3, 4]
>>> sequence = list([1, 2, 3, 4])
>>> for combination in abjad.enumerate.yield_combinations(
...     sequence,
...     maximum_length=2,
... ):
...     combination
... 
[]
[1]
[2]
[1, 2]
[3]
[1, 3]
[2, 3]
[4]
[1, 4]
[2, 4]
[3, 4]
>>> sequence = list([1, 2, 3, 4])
>>> for combination in abjad.enumerate.yield_combinations(
...     sequence,
...     minimum_length=2,
...     maximum_length=2,
... ):
...     combination
... 
[1, 2]
[1, 3]
[2, 3]
[1, 4]
[2, 4]
[3, 4]
>>> sequence = list("text")
>>> for combination in abjad.enumerate.yield_combinations(sequence):
...     "".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.

abjad.enumerate.yield_pairs(argument)[source]

Yields pairs sequence items.

Without duplicate items:

>>> for pair in abjad.enumerate.yield_pairs([1, 2, 3, 4]):
...     pair
... 
[1, 2]
[1, 3]
[1, 4]
[2, 3]
[2, 4]
[3, 4]

With duplicate items:

>>> for pair in abjad.enumerate.yield_pairs([1, 1, 1]):
...     pair
... 
[1, 1]
[1, 1]
[1, 1]

Length-1 sequence:

>>> for pair in abjad.enumerate.yield_pairs([1]):
...     pair
... 

Empty sequence:

>>> for pair in abjad.enumerate.yield_pairs([]):
...     pair
... 

Returns generator of length-2 sequences.

abjad.enumerate.yield_partitions(argument)[source]

Yields partitions of sequence.

>>> for partition in abjad.enumerate.yield_partitions([0, 1, 2]):
...     partition
... 
[[0, 1, 2]]
[[0, 1], [2]]
[[0], [1, 2]]
[[0], [1], [2]]
>>> for partition in abjad.enumerate.yield_partitions([0, 1, 2, 3]):
...     partition
... 
[[0, 1, 2, 3]]
[[0, 1, 2], [3]]
[[0, 1], [2, 3]]
[[0, 1], [2], [3]]
[[0], [1, 2, 3]]
[[0], [1, 2], [3]]
[[0], [1], [2, 3]]
[[0], [1], [2], [3]]

Returns generator of nested sequences.

abjad.enumerate.yield_permutations(argument)[source]

Yields permutations of sequence.

>>> for permutation in abjad.enumerate.yield_permutations([1, 2, 3]):
...     permutation
... 
[1, 2, 3]
[1, 3, 2]
[2, 1, 3]
[2, 3, 1]
[3, 1, 2]
[3, 2, 1]

Returns sequence generator.

abjad.enumerate.yield_set_partitions(argument)[source]

Yields set partitions of sequence.

>>> for set_partition in abjad.enumerate.yield_set_partitions([21, 22, 23, 24]):
...     set_partition
... 
[[21, 22, 23, 24]]
[[21, 22, 23], [24]]
[[21, 22, 24], [23]]
[[21, 22], [23, 24]]
[[21, 22], [23], [24]]
[[21, 23, 24], [22]]
[[21, 23], [22, 24]]
[[21, 23], [22], [24]]
[[21, 24], [22, 23]]
[[21], [22, 23, 24]]
[[21], [22, 23], [24]]
[[21, 24], [22], [23]]
[[21], [22, 24], [23]]
[[21], [22], [23, 24]]
[[21], [22], [23], [24]]

Returns set partitions in order of restricted growth function.

Returns generator of list of lists.

abjad.enumerate.yield_subsequences(argument, minimum_length=0, maximum_length=None)[source]

Yields subsequences of sequence.

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

Returns sequence generator.