You could use numpy.random.choice to randomly select elements where you want the replacements to occur in the original list. Then zip those indexes against the values you want to use for the substitution and apply the replacements.
from numpy.random import choice
def swap_elements(x, t):
new_x = x[:]
for idx, value in zip(choice(range(len(x)), size=len(t), replace=False), t_list):
new_x[idx] = value
return new_x
Example usage
>>> x_list = ['a', 'b', 'c', 'd', 'e']
>>> t_list = ['z', 'y', 'u']
>>> swap_elements(x_list, t_list)
['y', 'u', 'z', 'd', 'e']
>>> swap_elements(x_list, t_list)
['y', 'b', 'z', 'u', 'e']
>>> swap_elements(x_list, t_list)
['y', 'b', 'z', 'u', 'e']
>>> swap_elements(x_list, t_list)
['a', 'u', 'z', 'y', 'e']
x_list[2] = t_list[0]t_listare included in the new list, and b) That those elements are in order?ainx_listand it got replaced withz- do all values get replaced byz? If the length of the two lists are the same - is a straight replacement a correct answer. What if there's less elements inxthant... Do the elements ofthave to appear in order inx... etc...?