Python - Remove empty strings from list of strings Last Updated : 09 Jan, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report When working with lists of strings in Python, you may encounter empty strings (" ") that need to be removed. We'll explore various methods to Remove empty strings from a list. Using List ComprehensionList comprehension is the most concise and efficient method to filter out empty strings. This method is ideal for most scenarios due to its simplicity and efficiency. Python a = ["Geeks", "", "for", " ", "Geeks", ""] # Remove empty strings a = [x for x in a if x.strip()] print(a) Output['Geeks', 'for', 'Geeks'] Explanation:The strip() method removes leading and trailing whitespaces.The condition if x.strip() checks for non-empty strings after removing whitespaces.The filtered list contains only valid strings.Let's explore some more methods to remove empty strings from list of stringsTable of ContentUsing filter() Using remove() Using filter() with NoneUsing filter()filter() function works well when combined with a lambda function. Use this method for functional programming scenarios. Python a = ["Geeks", "", "for", " ", "Geeks", ""] # Remove empty strings a = list(filter(lambda x: x.strip(), a)) print(a) Output['Geeks', 'for', 'Geeks'] Explanation:lambda x: x.strip() function checks if a string is non-empty after stripping whitespaces.filter() filters out the strings that do not meet the condition.Using remove()remove() method can be used in a loop to delete empty strings iteratively. This method is useful when modifying the original list directly. Python a = ["Geeks", "", "for", " ", "Geeks", ""] # Remove empty strings for x in a[:]: if not x.strip(): a.remove(x) print(a) Output['Geeks', 'for', 'Geeks'] Explanation:Iterates over a copy of the list (a[:]) to avoid modification issues.not x.strip() identifies empty strings to be removed.Using filter() with None filter() function can directly filter out falsy values like empty strings when used with None. Python a = ["Geeks", "", "for", " ", "Geeks", ""] # Remove empty strings a = list(filter(None, map(str.strip, a))) print(a) Output['Python', 'is', 'fun!'] Explanation:map(str.strip, a) removes leading and trailing whitespaces from all strings.filter(None, ...) removes all falsy values (e.g., empty strings, None). Comment More infoAdvertise with us Next Article Python - Remove empty strings from list of strings M manjeet_04 Follow Improve Article Tags : Python python-list Python list-programs Python string-programs Practice Tags : pythonpython-list Similar Reads Python | Remove Redundant Substrings from Strings List Given list of Strings, task is to remove all the strings, which are substrings of other Strings. Input : test_list = ["Gfg", "Gfg is best", "Geeks", "for", "Gfg is for Geeks"] Output : ['Gfg is best', 'Gfg is for Geeks'] Explanation : "Gfg", "for" and "Geeks" are present as substrings in other strin 5 min read Remove empty tuples from a list - Python The task of removing empty tuples from a list in Python involves filtering out tuples that contain no elements i.e empty. For example, given a list like [(1, 2), (), (3, 4), (), (5,)], the goal is to remove the empty tuples () and return a new list containing only non-empty tuples: [(1, 2), (3, 4), 3 min read How to Remove Letters From a String in Python Removing letters or specific characters from a string in Python can be done in several ways. But Python strings are immutable, so removal operations cannot be performed in-place. Instead, they require creating a new string, which uses additional memory. Letâs start with a simple method to remove a s 3 min read Remove Last Element from List in Python Given a list, the task is to remove the last element present in the list. For Example, given a input list [1, 2, 3, 4, 5] then output should be [1, 2, 3, 4]. Different methods to remove last element from a list in python are:Using pop() methodUsing Slicing TechniqueUsing del OperatorUsing Unpacking 2 min read Remove falsy values from a list in Python Removing falsy values from a list filters out unwanted values like None, False, 0 and empty strings, leaving only truthy values. It's useful for data cleaning and validation.Using List ComprehensionList comprehension is a fast and efficient way to remove falsy values from a list . It filters out val 1 min read Like