I’m learning how to use the Twitter API using tweepy. I’ve produced a list of recent tweets with the keyword "tea garden" . From this list I want to search for strings in the tweets that include all capitalization variants of those strings.
My initial list of tweets w/ keywords
public_tweets = api.search("tea garden", count=200)
What do I add in this code to search for all upper/lowercase variants of the string? In this example, it would add tweets to the list that contained "Garden Tea" or "GARDEN TEA".
list = []
for tweet in public_tweets:
if "garden tea" in tweet.text:
list.append(tweet)
2
Answers
you can use
str.lower
to convert it to lowercase first, then compare:you can use
str.upper
to convert it to uppercase first, then compare: