I want to remove all empty strings from a list of strings in python.
My idea looks like this:
while \'\' in str_list:
str_list.remove(\'\')
Using a list comprehension is the most Pythonic way:
>>> strings = ["first", "", "second"]
>>> [x for x in strings if x]
['first', 'second']
If the list must be modified in-place, because there are other references which must see the updated data, then use a slice assignment:
strings[:] = [x for x in strings if x]