-4

I wanted to know if there is a way to do the following in python or something similar:

wordList = ['hello', 'hi', 'who', 'what']
message = "I don't know what you mean"
if any item of wordList is in message :
     #Do whatever
else:
     #Don't do whatever

I'm sorry if I am not giving enough info this is my first question on stackoverflow.

Zade-Sama
  • 1
  • 2

1 Answers1

0

Here this is an example of what you want

wordsInMessage = [words for words in wordList if words in message]

Basically if you want me to break this down

wordList = ['hello', 'hi', 'who', 'what']
message = "I don't know what you mean"
#create list where similar words will go
wordsInMessage = []
#iterate through wordList
for words in wordList:
    #if any way is in message
    if words in message:
        #put that word in the list created above
        wordsInMessage.append(words)
Buddy Bob
  • 5,829
  • 1
  • 13
  • 44