how to find integer number from list in python code example
Example 1: 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']
Example 2: python int in list
myList = [1,2,3,4,5]
if 3 in myList:
print("3 is present")