我想执行以下操作:
thing = "hello world" A = ["e","l"] B = ["l","e"] newthing = thing.replace(A,B) print(newthing)
然后应该很高兴地输出了输出,但是似乎不允许使用数组替换作为输入。有没有办法像这样继续做呢?
这将起作用:
newthing = thing for a,b in zip(A,B): newthing = newthing.replace(a,b)