overwrite_elements

sequencetools.overwrite_elements(sequence, pairs)

Overwrites sequence elements at indices according to pairs.

Example 1. Overwrites range elements:

>>> pairs = [(0, 3), (5, 3)]
>>> sequencetools.overwrite_elements(range(10), pairs)
[0, 0, 0, 3, 4, 5, 5, 5, 8, 9]

Returns list.

Example 2. Overwrites list elements:

>>> pairs = [(0, 3), (5, 3)]
>>> sequencetools.overwrite_elements(list(range(10)), pairs)
[0, 0, 0, 3, 4, 5, 5, 5, 8, 9]

Returns new list.

Example 3. Overwrites tuple elements:

>>> pairs = [(0, 3), (5, 3)]
>>> sequencetools.overwrite_elements(tuple(range(10)), pairs)
[0, 0, 0, 3, 4, 5, 5, 5, 8, 9]

Returns list.

Set pairs to a list of (anchor_index, length) pairs.

Coerces input to list.

Returns new list.