gpt4 book ai didi

python - 在 Python 列表中查找并替换为多个字符串值

转载 作者:太空宇宙 更新时间:2023-11-04 05:42:04 25 4
gpt4 key购买 nike

<分区>

非常喜欢这个question除了我想用 '' 替换 words 中与 error_list 中任何内容匹配的任何部分。

error_list = ['[br]', '[ex]', 'Something']
words = ['how', 'much[ex]', 'is[br]', 'the', 'fish[br]', 'noSomething', 'really']

期望的输出是

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

我徒劳的尝试是,

words = [w.replace(error_list , '') for w in word]

编辑:也许我还应该说我已经用循环完成了这个,但正在寻找一种更像 pythonic 的方式。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com