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 Palen
  • 2,645
  • 6
  • 31
  • 50

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
  • 1,048,767
  • 296
  • 4,058
  • 3,343