How to keep only none falsy numbers in a list with Python

1 Answer

0 votes
lst = [5, 6, None, "javascript", "", None, 9, None, None, 0, None, 8, 3.14, 85]

# Filter out non-numeric or "falsy" values
lst = list(filter(lambda x: isinstance(x, (int, float)) and x != 0, lst))

print(lst)



'''
run:
 
[5, 6, 9, 8, 3.14, 85]
 
'''

 



answered Mar 19 by avibootz
...