如何从列表中删除非数字

问题描述:

a = [1,2,3,'aa']

i想得到[1,2,3]

a=[1,2,3,'aa']
i want to get [1,2,3]

尝试
a = [1,2,3,'aa']
new_items = [item for item in a if item.isdigit()]



这将为您提供一个包含数字的新列表。


This will give you a new list with numbers.