Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to integrate the .lower() function into a python script that checks for certain words?

I have a script that has a list of possible words, and an input, then checks for the words in the input but it only checks for the specific word, and I’m not sure how to integrate .lower() in it.

term = ["test1", "test2"]
raw_input = input()

if all(Variable in raw_input for Variable in term):
    print("Both words were found")
else:
    print("Couldn't find required words")

But I’d like to add a .lower() I’ve tried but can’t find a way. Thanks

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I hope this is what you are looking for.

term = ["test1", "test2"]
raw_input = input()

# check if all terms are in the input string including lower and upper case
if all(x.lower() in raw_input.lower() for x in term):
    print("Both words were found")
else:
    print("Couldn't find required words")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading