📜  如何从python代码示例中的列表中提取数字

📅  最后修改于: 2022-03-11 14:45:28.044000             🧑  作者: Mango

代码示例1
a = ['1 2 3', '4 5 6', 'invalid']
numbers = []
for item in a:
    for subitem in item.split():
        if(subitem.isdigit()):
            numbers.append(subitem)
print(numbers)

['1', '2', '3', '4', '5', '6']