2024-04-26 05:39:59 发布
网友
我有个单子:
words = ['how', 'much', 'is[br]', 'the', 'fish[br]', 'no', 'really']
我想用一些类似于<br />的奇异值替换[br],从而得到一个新列表:
<br />
[br]
words = ['how', 'much', 'is<br />', 'the', 'fish<br />', 'no', 'really']
words = [w.replace('[br]', '<br />') for w in words]
这些被称为List Comprehensions。
除了列表理解,您还可以尝试映射
>>> map(lambda x: str.replace(x, "[br]", "<br/>"), words) ['how', 'much', 'is<br/>', 'the', 'fish<br/>', 'no', 'really']
例如,您可以使用:
words = [word.replace('[br]','<br />') for word in words]
这些被称为List Comprehensions。
除了列表理解,您还可以尝试映射
例如,您可以使用:
相关问题 更多 >
编程相关推荐