I have a list of items with heterogeneous data types contained in strings.
lst=['1','err','-1',' ','155']
From that, I would like to obtain a new list with only the positive numbers: new_lst=[1,155]
I have tried to avoid negative numbers as shown below. However, I am not able to avoid the strings and empty strings:
lst1=int(lst)
for i in lst1:
if i<0:
print i
else:
continue
Traceback (most recent call last):
File "C:/Users/Dev/Documents/Assignment-2/test-2.py", line 22, in <module>
c3=int(row[3])
ValueError: invalid literal for int() with base 10: 'err'
>>>