How to check if a word is in a list composed of words and sentences in python ?

Active March 29, 2021    /    Viewed 2915    /    Comments 0    /    Edit


Example of how to check if a word is in a list of words and sentences in python

Check if a word is in a list of words and sentences

Let's consider the followinf list:

mylist = ['hello', 'hola', 'hi, how are you today ?']

to check for example if the word 'today' is in the list a solution is to do

myword = 'today'

any(myword in w for w in mylist)

returns

True

ANother example:

myword = 'bonjour'

any(myword in w for w in mylist)

returns

False

References


Card image cap
profile-image
Daidalos

Hi, I am Ben.

I have developed this web site from scratch with Django to share with everyone my notes. If you have any ideas or suggestions to improve the site, let me know ! (you can contact me using the form in the welcome page). Thanks!



Did you find this content useful ?, If so, please consider donating a tip to the author(s). MoonBooks.org is visited by millions of people each year and it will help us to maintain our servers and create new contents.

Amount