Question:
I have a list:
['', 'apple', '', ' ', 'banana', '', ' ', 'pine', '', ' ', 'price', '', ' ']
How do I remove ''
and ' '
from the list?
Answer:
in functional style:
res = list(filter(len, map(str.strip, lst)))
print(res)
>>> ['apple', 'banana', 'pine', 'price']