How to Remove Empty String from List in Python?

Published On: 10/11/2022 | Category: Python


Hi Guys,

Now, let's see post of python remove empty value from list. if you want to see example of how to remove empty string from list in python then you are a right place. you can understand a concept of python remove empty string from list. we will help you to give example of how to remove empty string from list in python.

In Python, empty string values can be removed from the list in a number of different methods. To remove empty strings from a list, we will make use of the filter(), join(), and remove() functions. So let's look at the samples below.

So let's see bellow example:

Example 1:

main.py
myList = ['', 'Tuts-Station.com', '', 'is', 'Best', '']
  
# Remove Empty Value from List
newList = list(filter(None, myList))
  
print(newList)
Output
['Tuts-Station.com', 'is', 'Best']

Example 2:

main.py
myList = ['', 'Tuts-Station.com', '', 'is', 'Best', '']
  
# Remove Empty Value from List
newList = ' '.join(myList).split()
  
print(newList)
Output
['Tuts-Station.com', 'is', 'Best']

Example 3:

main.py
myList = ['', 'Tuts-Station.com', ' ', 'is', 'Best', '']
  
# Remove Empty Value from List
while("" in myList) :
    myList.remove("")
  
print(myList)
Output
['Tuts-Station.com', 'is', 'Best']

It will help you....

Happy Pythonic Coding!