Your question is a good example of a for
loop with else
clause. Please note: the indentation is valid, the else
belongs to the for
statement.
llw = [['apples','bananas'],['watermelons','melons']]
wordlist = ['bananas','strawberys','appricots','melons','watermelons']
for item in llw:
for word in item:
if word not in wordlist:
print(f'{word} not in wordlist, skipping list {item}')
break
else:
print(f'{item} was found in wordlist')
Out:
apples not in wordlist, skipping list ['apples', 'bananas']
['watermelons', 'melons'] was found in wordlist
CLICK HERE to find out more related problems solutions.