Answers for "get number from list python"

0

how to extract numbers from a list in python

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']
Posted by: Guest on August-12-2020

Code answers related to "get number from list python"

Python Answers by Framework

Browse Popular Code Answers by Language