split_sequence

sequencetools.split_sequence(sequence, weights, cyclic=False, overhang=False)

Splits sequence by weights.

Example 1. Splits sequence cyclically by weights with overhang:

>>> sequencetools.split_sequence(
...     (10, -10, 10, -10),
...     (3, 15, 3),
...     cyclic=True,
...     overhang=True,
...     )
((3,), (7, -8), (-2, 1), (3,), (6, -9), (-1,))

Example 2. Splits sequence cyclically by weights without overhang:

>>> sequencetools.split_sequence(
...     (10, -10, 10, -10),
...     (3, 15, 3),
...     cyclic=True,
...     overhang=False,
...     )
((3,), (7, -8), (-2, 1), (3,), (6, -9))

Example 3. Splits sequence once by weights with overhang:

>>> sequencetools.split_sequence(
...     (10, -10, 10, -10),
...     (3, 15, 3),
...     cyclic=False,
...     overhang=True,
...     )
((3,), (7, -8), (-2, 1), (9, -10))

Example 4. Splits sequence once by weights without overhang:

>>> sequencetools.split_sequence(
...     (10, -10, 10, -10),
...     (3, 15, 3),
...     cyclic=False,
...     overhang=False,
...     )
((3,), (7, -8), (-2, 1))

Example 5. Splits list once by weights without overhang:

>>> sequencetools.split_sequence(
...     [10, -10, 10, -10],
...     (3, 15, 3),
...     cyclic=False,
...     overhang=False,
...     )
[[3], [7, -8], [-2, 1]]

Returns new object of sequence type with elements also of sequence type.