I am looking for a function like string.replace, but for lists.
For example, with string.replace:
>>> s="abcd abcd"
>>> s.replace("bc", "XYZ")
'aXYZd aXYZd'
So the list version of the same thing would be like this:
>>> l=['a','b','c','d',' ', 'a','b','c','d']
>>> l.replace(['b','c'], ['X','Y','Z'])
['a','X','Y','Z',d,' ','a','X','Y','Z',d]
Note: this is not just substituting single elements of the list with something else. It is replacing all occurrences of a sublist with a different sublist potentially having a different length - just like string.replace() does for substrings.
(The lists I'm actually working with are not actually lists of characters so converting to/from strings won't work.)