[英]Python, separating all lowercase string at position where the upper string is
[英]How to search for all upper & lowercase versions of a string in Python?
我正在學習如何通過tweepy使用Twitter API。 我已經生成了關鍵字為“茶園”的最新推文列表。 從此列表中,我想在推文中搜索包含這些字符串的所有大寫變體的字符串。
public_tweets = api.search("tea garden", count=200)
list = []
for tweet in public_tweets:
if "garden tea" in tweet.text:
list.append(tweet)
您可以使用str.lower
首先將其轉換為小寫,然后進行比較:
list = []
for tweet in public_tweets:
if "garden tea" in tweet.text.lower():
list.append(tweet)
您可以使用str.upper
首先將其轉換為大寫,然后進行比較:
list = []
for tweet in public_tweets:
if "GARDEN TEA" in tweet.text.upper():
list.append(tweet)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.