2 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
你可以這樣使用,
a = ['BOOL_CONST_GROUP
| |\n',
'BOOL_GROUP
| |\n',
'BOOL_TEXT_GROUP
| |\n',
'FIXED_DATA_GROUP
| |\n',
'PATTERN_PF0
| |\n',
'BOOL_Partition
| |\n',
'VVS_Data_Z_Partition
| |\n']
a = [i.split('')[0] for i in a]
print(a)
輸出如你所愿。

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試這個(gè):
import re
x=['BOOL_CONST_GROUP | |\n',
'BOOL_GROUP | |\n',
'BOOL_TEXT_GROUP | |\n',
'FIXED_DATA_GROUP | |\n',
'PATTERN_PF0 | |\n',
'BOOL_Partition | |\n',
'VVS_Data_Z_Partition | |\n']
x=[re.sub('[^A-Za-z0-9]+','',i) for i in x]
print(x)
添加回答
舉報(bào)