查找和替换列表中的字符串值 [英] Find and replace string values in list
本文介绍了查找和替换列表中的字符串值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了这个清单:
words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really']
我想用一些与<br />
类似的奇妙值替换[br]
,从而得到一个新列表:
What I would like is to replace [br]
with some fantastic value similar to <br />
and thus getting a new list:
words = ['how', 'much', 'is<br />', 'the', 'fish<br />', 'no', 'really']
推荐答案
words = [w.replace('[br]', '<br />') for w in words]
这些被称为列表理解.
这篇关于查找和替换列表中的字符串值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文