Remove empty strings from a list of strings
Given:
str_list = ["Emma", "Jon", "", "Kelly", None, "Eric", ""]
Expected Output:
Original list of sting
['Emma', 'Jon', '', 'Kelly', None, 'Eric', '']
After removing empty strings
['Emma', 'Jon', 'Kelly', 'Eric']
Hint:
filter()
to remove empty strings from a listif
condition to remove the empty strings from a listSolution1:Using the loop and
if
conditionSolution2:Using the built-in function
need an explanation for this answer? contact us directly to get an explanation for this answerfilter()