这些项目在列表中 SF-04-08-010-MD01, AHU-VVIP-02-003-MD03, AHU-02-17-019-DPS03, AHU-T3-01-PL-TS01, EF-03-32-108-MD01, AHU-02-16-019-MD01, AHU-T3-01-003-MD01, SF-04-08-010-MD01, AHU-VVIP-02-003-MD03,
所以我想要一个新的列表,它应该像
SF-04-08
AHU-VVIP
AHU-02-17
AHU-T3-01
EF-03-32
AHU-02-16
AHU-T3-01
SF-04-08
AHU-VVIP-02
使用python吗?
答案 0 :(得分:1)
您可以使用如下所示的条带:
data = ['SF-04-08-010-MD01',
'AHU-VVIP-02-003-MD03',
'AHU-02-17-019-DPS03'
]
for item in data:
print ('-'.join(item.split('-')[:3]))
输出:
SF-04-08
AHU-VVIP-02
AHU-02-17