Removing empty strings from a Python list
To remove the empty strings from a list, we can use the built-in filter()
function in python.
Here is an example that removes the two empty strings from the below list.
stringList = ["Hello", "", "fun","","king"]
remove = filter(None, stringList) # returns iterator
print(list(remove))
Output:
["Hello","fun","king"]