我得到了这个 list :

words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really']

我想要用一些类似于[br]的奇妙值替换<br />,从而得到一个新列表:
words = ['how', 'much', 'is<br />', 'the', 'fish<br />', 'no', 'really']

最佳答案

words = [w.replace('[br]', '<br />') for w in words]

这些称为List Comprehensions

关于python - 查找和替换列表中的字符串值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3136689/

10-11 22:56
查看更多