【发布时间】:2019-01-24 15:41:55
【问题描述】:
我有一个演讲列表,我想删除所有在 (a)..(z)、(A)..(Z) 和 (i)...(九)。我找不到正确的正则表达式匹配来包含所有这些可能性。我试过没有成功:
list = [item for item in list if '(\w)' in item]
我应该一个一个地做,还是有更有效的方法? 谢谢!
【问题讨论】:
-
您必须使用
re模块。"(\w)" in item在item中查找文字字符串"(\w)"。 -
请提供示例输入和预期响应
-
我的列表如下
list=['this is the first (a) sentence', 'this is the second (b) sentence', 'this is the third sentence']我想剔除所有包含(a)和(b)等表达式的列表元素,以便恢复list=['this is the third sentence']