<分区>
非常喜欢这个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 的方式。