I would use filter
:
str_list = filter(None, str_list)
str_list = filter(bool, str_list)
str_list = filter(len, str_list)
str_list = filter(lambda item: item, str_list)
Python 3 returns an iterator from filter
, so should be wrapped in a call to list()
str_list = list(filter(None, str_list))
Related Contents:
- Why is it string.join(list) instead of list.join(string)?
- How to convert list to string [duplicate]
- How do I concatenate (join) items in a list to a single string?
- How to check if a string is a substring of items in a list of strings
- How would you make a comma-separated string from a list of strings?
- Alphabet range in Python
- How do I split a string into a list of characters?
- How to concatenate (join) items in a list to a single string
- How can I convert each item in the list to string, for the purpose of joining them? [duplicate]
- Splitting on last delimiter in Python string?
- Check if string ends with one of the strings from a list
- str.startswith with a list of strings to test for
- Split a string by a delimiter in python
- Removing a list of characters in string
- What exactly does the .join() method do?
- Case insensitive ‘in’
- case-insensitive list sorting, without lowercasing the result?
- How do I check if there are duplicates in a flat list?
- Find and replace string values in list [duplicate]
- How to convert a string with comma-delimited items to a list in Python?
- Create nice column output in python
- Python: how to print range a-z?
- Finding a substring within a list in Python [duplicate]
- Using Python String Formatting with Lists
- Pandas DataFrame stored list as string: How to convert back to list
- Confused about __str__ on list in Python [duplicate]
- How do I convert a list into a string with spaces in Python?
- Python: How to check a string for substrings from a list? [duplicate]
- Get the first character of the first string in a list?
- How slow is Python’s string concatenation vs. str.join?
- Converting a String to a List of Words?
- Converting a string representation of a list into an actual list object [duplicate]
- Python: find closest string (from a list) to another string
- Join a list of strings in python and wrap each string in quotation marks
- Joining pairs of elements of a list [duplicate]
- How do I serialize a Python dictionary into a string, and then back to a dictionary?
- Check if substring is in a list of strings?
- Loop “Forgets” to Remove Some Items [duplicate]
- Perform a string operation for every element in a Python list
- Simplest way of checking for string that contains a string in list? [duplicate]
- How to apply __str__ function when printing a list of objects in Python [duplicate]
- How to convert a string of space- and comma- separated numbers into a list of int?
- I want to replace single quotes with double quotes in a list
- How can I convert string values from a dictionary, into int/float datatypes?
- Return a variable in a Python list with double quotes instead of single
- Pandas Series of lists to one series
- Column of lists, convert list to string as a new column
- How can I get list of values from dict?
- Split list into smaller lists (split in half)
- Why do tuples take less space in memory than lists?