cogwheel.utils.replace

cogwheel.utils.replace(sequence, *args)

Replace specified elements in a sequence with new values.

Return a list like sequence with the first occurrence of old0 replaced by new0, the first occurrence of old1 replaced by new1, and so on, where old0, new0, old1, new1, ... = args. Accepts an even number of arguments.

Parameters:
sequencelist or iterable

The input sequence to modify.

*argslist

Pairs of old and new elements to replace in the sequence.

Returns:
list

A copy of sequence with the specified replacements.

Raises:
ValueError

If an odd number of args is provided or if any old value is not found in the sequence.