「for」および「if」ループの山全体なしで、あるリストの要素を別のリストの要素と照合するためのPythonソリューションを見つけるのに問題があります。これを行うためのより良い方法を見つけることを望んでいます。一致を実行するために複数のリストを通過する大きな反復ループがいくつかあります。試合では、リストの要素を削除したい。以下に 2 つの例を示します。
def score_and_retweet(auth):
api = tweepy.API(auth)
for tweet in api.home_timeline(count=100, include_rts=0):
for goodword in tweet_whitelist:
if goodword in tweet.text and tweet.retweet_count >= 2:
try:
api.retweet(tweet.id_str)
except tweepy.error.TweepError:
error_id = tweet.id_str
と
t = time.localtime()
if t.tm_hour is 14 and (t.tm_wday is 1 or t.tm_wday is 4):
htmlfiles = glob.glob(html_file_dir+'/*.html')
for file in htmlfiles:
for badword in filename_badwords:
if badword in file:
try:
htmlfiles.remove(file)
except ValueError:
error = "already removed"