How to check if a list has an empty string
list, python, string
Solution
You can just check if there is the element `''` in the list:
if '' in lst:
# ...
if '' in lst[:1]: # for your example
# ...
Here is an example:
>>> lst = ['John', '', 'Foo', '0']
>>> lst2 = ['John', 'Bar', '0']
>>> '' in lst
True
>>> '' in lst2
False
Problem
Suppose I have a list `['', 'Tom', 'Jane', 'John', '0']`, and I wrote the following to check if it has empty string `''`: ``` if any('' in s for s in row[1:]): print "contains empty string, continue now" continue ``` I expect this to only pick the empty string, but this also picks a list that contains '0'. The '0' string is valid and I do not want to filter it out. So how can I check for an empty string in a python list?