1

我有一个清单

['PFRMAT,RR', 'TARGET,', 'AUTHOR,5014-2892-3830', 'MODEL,1', 'TGAHPAFKYLAQTSGKEPTWNFWKYLVAPDGKVVGAWDPTVSVEEVRPQI', 'TALVR', '3,9', '3,16', '3,17', '3,18', '3,21', '3,25', '3,26', '3,27', '3,28', '3,29', '3,30']

如何删除字符串字母,因此列表变为['3,9','3,16','3,17','3,18'] 我不想使用删除前 6 个元素的函数,例如del开头的字母字符串数量不是固定数量

4

1 回答 1

7
[elem for elem in my_list if not any(c.isalpha() for c in elem)]

takes my_list and returns a new list with all elements that have no letters in it. It is a list comprehension (thanks @Lattyware) returning a new list, so you probably want to return it back to my_list:

my_list = [elem for elem in my_list if not any(c.isalpha() for c in elem)]
于 2013-04-22T15:40:44.553 回答