简体   繁体   中英

remove letters from a list

I have a list

['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']

How can I remove the string letters, so the list becomes ['3,9','3,16','3,17','3,18'] I don't want to use a function that removes the first 6 elements like del as the amount of string of letters at the start isn't a fixed amount

[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)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM