In python, what is the best way to replace an element in a list with the elements from another list?
For example, I have:
a = [ 1, 'replace_this', 4 ]
I want to replace replace_this
with [2, 3]
. After replacing it must be:
a = [ 1, 2, 3, 4 ]
Update
Of course, it is possible to do with slicing (I'm sorry that I didn't write it in the question), but the problem is that it is possible that you have more than one replace_this
value in the list. In this case you need to do the replacement in a loop and this becomes unoptimal.
I think that it would be better to use itertools.chain
, but I'm not sure.