words = ['Duration12', 'Noun1', 'Adjective7']
result = [word[:-2] for word in words]
给我
['Duration', 'Nou', 'Adjectiv']
但我想得到
['Duration', 'Noun', 'Adjective']
是否有任何库函数可以实现它,或者我应该显式检测可用的数字然后删除它们?
最佳答案
试试这个:
In [8]: from string import digits
In [9]: remove_digits = str.maketrans('', '', digits)
In [10]: [word.translate(remove_digits) for word in words]
Out[10]: ['Duration', 'Noun', 'Adjective']
有关更多信息,请参阅链接:Link
关于python - 删除字符串列表中的所有数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54503418/