repeat_elements

sequencetools.repeat_elements(sequence, indices=None, period=None, total=1)

Repeats sequence elements.

Example 1. Repeats elements at indices 1 and 2 a total of three times each:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     indices=[1, 2],
...     total=3,
...     )
[0, [1, 1, 1], [2, 2, 2], 3, 4, 5, 6, 7, 8, 9]

Example 2. Repeats elements at indices -1 and -2 a total of three times each:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     indices=[-1, -2],
...     total=3,
...     )
[0, 1, 2, 3, 4, 5, 6, 7, [8, 8, 8], [9, 9, 9]]

Example 3. Repeats elements at indices congruent to 1 and 2 (mod 5) a total of three times each:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     indices=[1, 2],
...     total=3,
...     period=5,
...     )
[0, [1, 1, 1], [2, 2, 2], 3, 4, 5, [6, 6, 6], [7, 7, 7], 8, 9]

Example 4. Repeats elements at indices congruent to -1 and -2 (mod 5) a total of three times each:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     indices=[-1, -2],
...     total=3,
...     period=5,
...     )
[0, 1, 2, [3, 3, 3], [4, 4, 4], 5, 6, 7, [8, 8, 8], [9, 9, 9]]

Example 5. Repeats all elements a total of two times each:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     total=2,
...     )
[[0, 0], [1, 1], [2, 2], [3, 3], [4, 4], [5, 5], [6, 6], [7, 7], [8, 8], [9, 9]]

Example 6. Repeats all elements a total of one time each:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     total=1,
...     )
[[0], [1], [2], [3], [4], [5], [6], [7], [8], [9]]

Example 7. Repeats all elements a total of zero times each:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     total=0,
...     )
[[], [], [], [], [], [], [], [], [], []]

Example 8. Repeats no elements:

>>> sequencetools.repeat_elements(
...     list(range(10)),
...     indices=[],
...     )
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Returns new object of sequence type.