Python Remove Empty String from List Example

By Hardik Savani October 30, 2023 Category : Python

In this short tutorial we will cover an python remove empty value from list. I explained simply step by step python remove empty string from list. you'll learn how to remove empty string from list in python. it's simple example of how to remove empty string in python.

There are several ways to remove empty string values from the list in python. we will use filter(), join() and remove() functions to delete empty string from list. so let's see the below examples.

You can use these examples with python3 (Python 3) version.

let's see a below a simple example with output:

Example 1:

main.py

myList = ['', 'ItSolutionStuff.com', '', 'is', 'Best', '']
  
# Remove Empty Value from List
newList = list(filter(None, myList))
  
print(newList)

Output:

['ItSolutionStuff.com', 'is', 'Best']

Example 2:

main.py

myList = ['', 'ItSolutionStuff.com', '', 'is', 'Best', '']
  
# Remove Empty Value from List
newList = ' '.join(myList).split()
  
print(newList)

Output:

['ItSolutionStuff.com', 'is', 'Best']

Example 3:

main.py

myList = ['', 'ItSolutionStuff.com', ' ', 'is', 'Best', '']
  
# Remove Empty Value from List
while("" in myList) :
    myList.remove("")
  
print(myList)

Output:

['ItSolutionStuff.com', 'is', 'Best']

I hope it can help you...

Tags :
Shares