You do not need to add another append(), de-indenting .append() in else clausule will do it - it will be always executed, regardless whether sum1 was defined in if or else.
And as you are using your if/else only to set value of sum1 to True/False, simpler way is to directly assign result of your condition into sum1:
And as you are using your if/else only to set value of sum1 to True/False, simpler way is to directly assign result of your condition into sum1:
for num in sal['JobTitle']: sum1 = 'chief' in num.lower() test.append(sum1)Or you can do it directly with test.append( 'chief' in num.lower() ) without using sum1 variable at all - but perhaps the code above is little easier to understand.