我在python中有一个列表,其中某些元素包含子字符串,如'Page 1 of 67‘,'Page 2 of 67’,依此类推,直到'Page 67 of 67‘。
list1 =“24/02/2021年|第1页,共67页|”,“保财保2- 100| 100| 500,000.00| 9,000.00| 750.00|",”建议者:样品代理012|版本7.14.0|第2页,共67页|“,”扣除费用“
output =“保财保2- 100| 100| 500,000.00| 9,000.00| 750.00|",”扣费“
发布于 2021-03-02 20:43:24
试试这个:
list1 = ["24/02/2021| Page 1 of 67|", "Wealth Protect Assure 2 - 100| 100| 500,000.00| 9,000.00| 750.00|", "Proposed By: Sample Agent 012| Ver 7.14.0| Page 2 of 67|", "Deduct fees & charges"]
print([i for i in list1 if "Page" not in i])输出:
['Wealth Protect Assure 2 - 100| 100| 500,000.00| 9,000.00| 750.00|', 'Deduct fees & charges']发布于 2021-03-02 21:22:40
导入re
pattern = re.compile(r"|第10页\d+ of \d+|") list1 =“24/02/2021年|第10页,共67页|”,“保财保2- 100| 100| 500,000.00| 9,000.00| 750.00|",”建议者:样品代理012|版本7.14.0|第20页,共67页|“,”扣除费用“
如果不是pattern.search(i),则对于list1中的i,过滤=i
打印(过滤)
https://stackoverflow.com/questions/66439566
复制相似问题