Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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

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

PREVIOUS NEXT
Code Example
Python :: pil image to numpy array 
Python :: Learn python 3 the hard way by by Zed Shaw 
Python :: np.hstack 
Python :: last history of whatsapp message with python 
Python :: python get index of first element of list that matches condition 
Python :: instagram login with selenium py 
Python :: export csv 
Python :: last element in list py 
Python :: pandas save one row 
Python :: display youtube video in jupyter notebook 
Python :: modulus of python complex number 
Python :: rename column pandas 
Python :: password manager python 
Python :: python ascii caesar cipher 
Python :: public in python 
Python :: iterate over list and select 2 values together python 
Python :: sort list of numbers python 
Python :: pyodbc sql save pandas dataframe 
Python :: read json from api python 
Python :: lecture de fichier python 
Python :: python list comprehension with if 
Python :: decision tree classifier 
Python :: pytorch freeze layers 
Python :: find average of list python 
Python :: pandas set condition multi columns 
Python :: python get memory address of variable 
Python :: python check if string is int 
Python :: ursina python 
Python :: check strings last letter python 
Python :: How to draw a rectangle in cv2 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =