作者:杨艳奎_718 | 来源:互联网 | 2023-09-16 10:19
我试图替换字符串中的子字符串,条件是被替换的值不在忽略列表中。例如,由于 id_1 在 ignore_list 中,因此不应替换 test_str 中的 'id_1' :
ignore_list = ['id_1']
test_str = "id_1Testid"
test_str = test_str.replace('id' , 'test2')
test_str
应该包含“ id_1Testtest2
”而不是“ test2_1Testtest2
”
如何更新,使得项目在ignore_list
其在test_str
不更换?