How to check if two given words are present in a string in Python

1 Answer

0 votes
def is_two_words_in_string(s: str, w1: str, w2: str) -> bool:
    # Checks if both words are present in the string
    return w1 in s and w2 in s

s = "Far out in the uncharted area of the end of the Western Spiral arm of the Galaxy"
w1 = "uncharted"
w2 = "Galaxy"

result = is_two_words_in_string(s, w1, w2)
print(result)



'''
run:

True

'''

 



answered Sep 12 by avibootz
...