partition_sequence_by_sign_of_elements

sequencetools.partition_sequence_by_sign_of_elements(sequence, sign=(-1, 0, 1))

Partitions sequence by sign of elements.

>>> sequence = [0, 0, -1, -1, 2, 3, -5, 1, 2, 5, -5, -6]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence))
[[0, 0], [-1, -1], [2, 3], [-5], [1, 2, 5], [-5, -6]]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence, sign=[-1]))
[0, 0, [-1, -1], 2, 3, [-5], 1, 2, 5, [-5, -6]]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence, sign=[0]))
[[0, 0], -1, -1, 2, 3, -5, 1, 2, 5, -5, -6]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence, sign=[1]))
[0, 0, -1, -1, [2, 3], -5, [1, 2, 5], -5, -6]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence, sign=[-1, 0]))
[[0, 0], [-1, -1], 2, 3, [-5], 1, 2, 5, [-5, -6]]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence, sign=[-1, 1]))
[0, 0, [-1, -1], [2, 3], [-5], [1, 2, 5], [-5, -6]]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence, sign=[0, 1]))
[[0, 0], -1, -1, [2, 3], -5, [1, 2, 5], -5, -6]
>>> list(sequencetools.partition_sequence_by_sign_of_elements(
...     sequence, sign=[-1, 0, 1]))
[[0, 0], [-1, -1], [2, 3], [-5], [1, 2, 5], [-5, -6]]

When -1 in sign, groups negative elements.

When 0 in sign, groups 0 elements.

When 1 in sign, groups positive elements.

Returns list of tuples of sequence element references.