我有以下短语列表:
[
'This is erleada comp. recub. con película 60 mg.',
'This is auxina e-200 uicaps. blanda 200 mg.',
'This is ephynalsol. iny. 100 mg.',
'This is paracethamol 100 mg.'
]
Run Code Online (Sandbox Code Playgroud)
我需要得到以下结果:
[
'This is erleada.',
'This is auxina.',
'This is ephynalsol.',
'This is paracethamol.'
]
Run Code Online (Sandbox Code Playgroud)
我编写了以下函数来清理短语:
def clean(string):
sub_strings = [".","iny","comp","uicaps]
try:
string = [string[:string.index(sub_str)].rstrip() for sub_str in sub_strings]
return string
except:
return string
Run Code Online (Sandbox Code Playgroud)
并按如下方式使用它:
for phrase in phrases:
drug = clean(phrase)
Run Code Online (Sandbox Code Playgroud)