You may use Python Regular Expression to search for blank entries on the list. A Regular Expression is a sequence of characters that define a pattern. For more information on Python Regular Expression, kindly visit: w3school link and Google Developer link
Kindly replace the following code
for c in customerlist: if not in c:
with the following code:
for i in range(len(customerlist)): for j in range(len(customer1)): emptylist = re.findall('\s*', customerlist[i][j])
Dont forget to include 'import re' at the beginning of code to import Python re module
The complete code:
import re customer1 = ['Dan','24','red'] customer2 = ['Bob',' ','Blue', ' '] customerlist = [customer1, customer2] for i in range(len(customerlist)): for j in range(len(customer1)): emptylist = re.findall('\s*', customerlist[i][j]) if(len(emptylist) == 0): print('There are no blank entries') else: print('There are blank entries') #code goes here to do something
The output:
There are blank entries
In the code:
emptylist = re.findall('\s*', customerlist[i][j])
re.findall() search for zero or more instances(*) of white space character(\s) with customerlist being the iterating list. customerlist[i][j] as it is a list of lists.