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

Published: March 29, 2021

Tags: Python; List;

DMCA.com Protection Status

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