【发布时间】:2019-11-15 11:41:03
【问题描述】:
我想将两个空列表之间的所有列表转换为一个列表。示例
[]
['The', 'tablets', 'are', 'filled', 'into', 'cylindrically', 'shaped', 'bottles', 'made', 'of', 'white', 'coloured']
['polyethylene.', 'The', 'volumes', 'of', 'the', 'bottles', 'depend', 'on', 'the', 'tablet', 'strength', 'and', 'amount', 'of']
['tablets,', 'ranging', 'from', '20', 'to', '175', 'ml.', 'The', 'screw', 'type', 'cap', 'is', 'made', 'of', 'white', 'coloured']
['polypropylene', 'and', 'is', 'equipped', 'with', 'a', 'tamper', 'proof', 'ring.']
[]
['PVC/PVDC', 'blister', 'pack']
[]
['Blisters', 'are', 'made', 'in', 'a', 'thermo-forming', 'process', 'from', 'a', 'PVC/PVDC', 'base', 'web.', 'Each', 'tablet']
['is', 'filled', 'into', 'a', 'separate', 'blister', 'and', 'a', 'lidding', 'foil', 'of', 'aluminium', 'is', 'welded', 'on.', 'The', 'blisters']
['are', 'opened', 'by', 'pressing', 'the', 'tablets', 'through', 'the', 'lidding', 'foil.', 'PVDC', 'foil', 'is', 'in', 'contact', 'with']
['the', 'tablets.']
[]
['Aluminium', 'blister', 'pack']
[]
我想要的第一个列表是:
['The', 'tablets', 'are', 'filled', 'into', 'cylindrically', 'shaped', 'bottles', 'made', 'of', 'white', 'coloured', 'polyethylene.', 'The', 'volumes', 'of', 'the', 'bottles', 'depend', 'on', 'the', 'tablet', 'strength', 'and', 'amount', 'of', 'tablets,', 'ranging', 'from', '20', 'to', '175', 'ml.', 'The', 'screw', 'type', 'cap', 'is', 'made', 'of', 'white', 'coloured','polypropylene', 'and', 'is', 'equipped', 'with', 'a', 'tamper', 'proof', 'ring.']
下一个列表变成:
['PVC/PVDC', 'blister', 'pack']
并且模式应该继续。 到目前为止的代码:
import csv, re
filepath = r'C:\Users\techj\Music\Data\Tagged\090388 (1.0,CURRENT,LATEST APPROVED.txt)'
with open(filepath) as f:
content = f.readlines()
# s = ' '.join(x for x in content if x)
# print(s)
for line in content:
line = line.split()
print(line)
【问题讨论】:
-
你能显示文件中的数据吗
标签: python regex list concatenation grouping