请教:以下程序想把str_a中含有str_b内容的部分替换为str_b2内容,但,执行后发现并没能成功替换,该如何才能实现呢?谢谢!
-- coding:utf-8 --
def test():
a=[('I', 'PRP'), ('am', 'VBP'), ('glad', 'JJ'), ('that', 'IN'), ('you', 'PRP'), ('have', 'VBP'), ('come', 'VBN'), ('.', '.')]
b=[('that', 'IN'), ('you', 'PRP'), ('have', 'VBP'), ('come', 'VBN')]
str_b = str(b)
print('str_b: ', str_b)
str_b2 = "('<', '<'), "+str_b[1:-1]+", ('>', '>')"
print('str_b2: ', str_b2)
str_a = str(a)
print('str_a: ', str_a)
str_c = str_a.replace(str_b, str_b2)
print('str_c: ', str_c)
if name == 'main':
test()