Nk SP
0
Q:

removing empty in list python

list2 = filter(None, list1)
2
# Python3 code to demonstrate  
# removing empty strings  
# using remove() 
  
# initializing list  
test_list = ["", "GeeksforGeeks", "", "is", "best", ""] 
  
# Printing original list 
print ("Original list is : " + str(test_list)) 
  
# using remove() to 
# perform removal 
while("" in test_list) : 
    test_list.remove("") 
      
# Printing modified list  
print ("Modified list is : " + str(test_list)) 
0
'''
This is a classic python3 doh!.

A filter is a special iterable object you can iterate over. However, much like a generator, you can iterate over it only once. So, by calling list(people2), you are iterating over each element of the filter object to generate the list. At this point, you've reached the end of the iterable and nothing more to return.
'''
0

New to Communities?

Join the community