1 回答
TA贡献1921条经验 获得超9个赞
也许,对 a 的简单拆分" "可能在这里可以正常工作:
import re
l = ['W –-Transportation',
'W23.F5-International_waterways W25.2-Airlines',
'W23.F8-Rivers W25.4-Bus_lines',
'W23.H-Pipelines W25.6-Railroads',
'W23.H2-Oil_pipelines W25.8-Shipping_lines',
'W23.H4-Natural_gas_pipelines W27-Transportation_safety',
'W23.H6-Water_pipelines W27.2-Traffic_safety',
'W23.K-Transportation_system_design W29-Navigation',
'W23.M-Transportation_system_construction W32-Transportation_research',
'W23.M2-Transportation_facility_construction W32.2-Transportation_surveys',
'W23.M4-Transportation_system_maintenance W34-Transportation_education',
'W23.M4.2-Road_maintenance W36-Transportation_policy',
'W23.M6-Transportation_system_repair W38-Transportation_planning',
'W23.M6.2-Vehicle_repair W40-Transportation_aspects',
'W25-Transportation_industry']
k = []
for i in l:
new_string = i.split(" ")
for j in new_string:
if j != '':
k.append(j.strip())
print(k)
输出
['W –-Transportation', 'W23.F5-International_waterways', 'W25.2-Airlines', 'W23.F8-Rivers', 'W25.4-Bus_lines', 'W23.H-Pipelines', 'W25.6-Railroads', 'W23.H2-Oil_pipelines', 'W25.8-Shipping_lines', 'W23.H4-Natural_gas_pipelines', 'W27-Transportation_safety', 'W23.H6-Water_pipelines', 'W27.2-Traffic_safety', 'W23.K-Transportation_system_design', 'W29-Navigation', 'W23.M-Transportation_system_construction', 'W32-Transportation_research', 'W23.M2-Transportation_facility_construction', 'W32.2-Transportation_surveys', 'W23.M4-Transportation_system_maintenance', 'W34-Transportation_education', 'W23.M4.2-Road_maintenance', 'W36-Transportation_policy', 'W23.M6-Transportation_system_repair', 'W38-Transportation_planning', 'W23.M6.2-Vehicle_repair', 'W40-Transportation_aspects', 'W25-Transportation_industry']
添加回答
举报