Removing Empty Strings From List of Strings

problem statement

While working with unstructured data, sometimes I need to split long string into list of short strings. In these cases new list might include empty strings. Here is quick solution to clean up the list of strings from empty ones.

issue example

Let’s say you have a list of strings which has elements as empty strings:

dirty_list = ["", "programming", "is", "", "an", "awesome", "craft"]

solution

We can clean up this list from empty strings using filter method from Python3

clean_list = list(filter(None, dirty_list))

New cleaned list:

['programming', 'is', 'an', 'awesome', 'craft']

source