Sometimes, we want to remove empty strings from a list of strings with Python.
In this article, we’ll look at how to remove empty strings from a list of strings with Python.
How to remove empty strings from a list of strings with Python?
To remove empty strings from a list of strings with Python, we can call the filter
function.
For instance, we write
str_list = list(filter(None, str_list))
to call filter
with None
and str_list
to return an iterator with the strings in str_list
that aren’t empty.
Then we convert the iterator to a list with list
.
Conclusion
To remove empty strings from a list of strings with Python, we can call the filter
function.