get all integers from list python code example
Example 1: python filter list of int and strings
def filter_list(l):
'return a new list with the strings filtered out'
return [i for i in l if not isinstance(i, str)]
Example 2: print only strings in list python
list1 = [1, 'string', 2, 'string2']
for ele in list1:
if(type(ele) == str):
print(ele)