我已經使用json從web讀取twitter數據,所以它是字典形式。我必須使用Python找到TweetID以300或700結尾的推文。我知道我必須使用正則表達式,但我不熟練使用正則表達式。任何人都可以幫忙嗎?使用正則表達式在Python中查找值
import re
with open("tweet37.txt", "w") as o:
for tweet in tweets:
tweet_id = tweet['id']
if tweet_id == re.compile(r'd*700' or 'd*300'):
print >> o, str(tweet['id'])
這沒有給出任何錯誤,但沒有匹配任何ID。輸出文件是空白的。
這就是ID的樣子。他們在微博中Tweet字典[ '身份證']
400051062968557600
400051063002116100
400051062985330700
謝謝,它的工作。 –