根据Python中另一个列表中的值替换字符串列表

根据Python中另一个列表中的值替换字符串列表,python,string,list,Python,String,List,我有一个相同字符串的列表,我想根据其他列表替换一些子字符串 my_lst = ['My name is Jack', 'My name is Jack', 'My name is Jack'] update_1 = ['My','Your','His'] update_2 = ['A','B','C'] my_lst_f = [r.replace("My", i) for r in my_lst for i in update_1][:3] my_lst_ff = [p.

我有一个相同字符串的列表,我想根据其他列表替换一些子字符串

my_lst = ['My name is Jack', 'My name is Jack', 'My name is Jack']

update_1 = ['My','Your','His']
update_2 = ['A','B','C']

my_lst_f = [r.replace("My", i) for r in my_lst for i in update_1][:3]
my_lst_ff = [p.replace("Jack", q) for p in my_lst_f for q in update_2][:3]
print(my_lst_ff)

--------
['My name is A', 'My name is B', 'My name is C']
我的预期产出是

['My name is A', 'Your name is B', 'His name is C']

我如何用Python实现这一点?谢谢你的帮助

mylst\uff=[value.replace(“my”,update\u 1[idx])。idx的替换(“Jack”,update\u 2[idx]),枚举中的值(mylst)]
mylst\uff=[value.replace(“my”,update\u 1[idx])。idx的替换(“Jack,update\u 2[idx]),枚举中的值(mylst)]/code>这应该可以:

my_lst_f = [r.replace("My", update_1[i]) for i,r in enumerate(my_lst)]
my_lst_ff = [p.replace("Jack", update_2[i]) for i,p in enumerate(my_lst_f)]
print(my_lst_ff)
这假设更新1、更新2和我的列表具有相同的长度。

这应该可以:

my_lst_f = [r.replace("My", update_1[i]) for i,r in enumerate(my_lst)]
my_lst_ff = [p.replace("Jack", update_2[i]) for i,p in enumerate(my_lst_f)]
print(my_lst_ff)

这假设更新1、更新2和我的列表具有相同的长度。

如果每个列表具有相同的长度,则最好采用@Daniel Konstantinov提出的方法。很高兴知道这一点!谢谢:)如果每个列表都有相同的长度,那么最好采用@Daniel Konstantinov提出的方法。很高兴知道这一点!谢谢:)