I’m using a twitter API and are scanning tweets to see if they contain a word which is in an array named ‘special’. The following code appears to work fine, but only indicates when it finds a match. How do I also get it to show both the particular word that matched, and the string that the word was contained in?
if any(word in tweet.body for word in special):
print "match found"
What I’d like is something along the lines of “the word BOB was found in the tweet ‘I am BOB'”
Cheers
3
Answers
This code will print all matched words for given tweet.
Updated snippet as per request in comment
Result:
Use regx appropriately
use re.IGNORECASE only if you need case insensitive search.