lst1=int(lst) is the code that lst1=int(lst) exception. This essentially tries to make a list in int (which you cannot do).
What you want to do is iterate over lst , and for each element, determine if the element can be inserted into int , and then check if the element (like int ) is positive.
You can do something like this:
lst = ['1','err','-1',' ','155'] new_lst = [] for i in lst: try: int_i = int(i)
EDIT : Added ValueError for completeness, see @BigZ answer.
source share