我已将行读入列表:
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']
现在对于每一行,我想捕获 2 个组,例如W23.F5-International_waterways,W25.2-Airlines并将它们分成两个列表条目。
我的预期结果是:
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', .....,'W25-Transportation_industry']
捕获组的正则表达式是,([a-z])\s*?([A-Z])但我应该如何将捕获组拆分为新的列表条目?
郎朗坤
相关分类