0

I'm using Python to try and check if a string contains certain words. It can contain all or some of the words.

listCall = ('Azura', 'Fly', 'yellow')
readME = 'the color is yellow'
if listCall in readME:
    print 'we found certain words'
else:
    print 'all good'
Melanie Shebel
  • 2,533
  • 6
  • 30
  • 49

1 Answers1

2

You are testing if the *whole list listCall* is inreadME`. You need to test for individual words instead:

if any(word in readME for word in listCall):

This uses a generator expression and the any() function to efficiently test individual words in listCall against the readME string.

Martijn Pieters
  • 963,270
  • 265
  • 3,804
  • 3,187