extract numbers from list of strings python string python code example
Example 1: how to seperate words and number in a list
ip=['a',1,2,3]
m=[]
n=[]
for x in range(0,len(ip):
if str(ip[x]).isdigit():
m.append(ip[x])
else:n.append(ip[x])
print(m,n)
Example 2: extract numbers from list of strings python using regex
new_list = [int(item) for sublist in a for item in sublist if item.isdigit()]