1 回答
TA贡献1865条经验 获得超7个赞
您可以使用一个简单for-loop的方法来完成此操作:
data = ['[infotype02]', 'lastModifiedOn = serial<customMapping>', 'customString18 = BADGE_NUMBER<move>', 'firstName = FIRST_NAME<move>',
'lastName = LAST_NAME<move>', 'customString29 = USER_NAME<move>', 'email = EMAIL_ADDRESS<move>', 'documenttype = DOC_TYPE<move>',
'documentnumber = DOC_SERIA<customMapping>', 'documentnumberx2 = DOC_NUMBER<customMapping>', 'issuedate = DOC_ISSUE_DATE<move>',
'issueauthority = DOC_ISSUER<move>', 'nationalId = CNP<move>', 'company = COMPANY<move>', 'phoneNumber = PHONE_NUMBER<move>',
'startDate = HIRE_DATE<customMapping>', 'startDatex2 = TERMINATION_DATE<customMapping>', '[/infotype02]', '[infotype02]',
'lastModifiedOn = serial<customMapping>', 'customString18 = BADGE_NUMBER<move>', 'firstName = FIRST_NAME<move>', 'lastName = LAST_NAME<move>',
'customString29 = USER_NAME<move>', 'email = EMAIL_ADDRESS<move>', 'documenttype = DOC_TYPE<move>', 'documentnumber = DOC_SERIA<customMapping>',
'documentnumberx2 = DOC_NUMBER<customMapping>', 'issuedate = DOC_ISSUE_DATE<move>', 'issueauthority = DOC_ISSUER<move>', 'nationalId = CNP<move>',
'company = COMPANY<move>', 'phoneNumber = PHONE_NUMBER<move>', 'startDate = HIRE_DATE<customMapping>', 'startDatex2 = TERMINATION_DATE<customMapping>',
'[/infotype02]']
new_list = []
for d in data:
if d[0] == '[' and not d[1] == '/':
#if re.match(r"\[[^/](.*)\]", d): # If you want to use `re`
new_list.append(d[1:-1])
print(new_list)
输出:
['infotype02', 'infotype02']
因为您在给定列表中有 2 个这些标签。
添加回答
举报