lundi 28 décembre 2020

Python syntax for “if a and b or a and c” where a, b and c are words in a sentence

I have a python script, and I should check if two words are present in a sentence separated by dash

test_dash_sentence="wordtest-wordtest-word3-word4"

if ("word1" and "word2") or ("word1" and "word3") in test_dash_sentence:
    print("FOUND")
else:
    print("NOT FOUND")

The issue I have is that is return me "FOUND" even if word1 is not present, so it should return me "NOT FOUND"

I have tried different models (with simple quotation, without parentheses) and it seems to work if I only look for one word in the sentence, but when I look for two words, it doesn't work.

Aucun commentaire:

Enregistrer un commentaire