Simd
Simd

Reputation: 21271

How to check for empty fields

I have an input file where each line has 4 fields separated by commas. For example

a,b,c,d

Unfortunately, a small number of lines are broken and are missing fields. For example

a,,c,d

I currently use split to put the fields into a list. How can I check if any of the entries in this list are now empty?

Upvotes: 0

Views: 291

Answers (2)

Alecg_O
Alecg_O

Reputation: 1039

Try something like this if you need to know which field is empty:

emptys_list = []

for i in range(len(list)):
    if list[i] == '':
        emptys_list.append[i]

return emptys_list

Upvotes: 1

falsetru
falsetru

Reputation: 369164

Using all, it will return False if there's any empty string. Otherwise True.

>>> all(['a', 'b', 'c', 'd'])
True
>>> all(['a', '', 'c', 'd'])
False

Upvotes: 4

Related Questions