【发布时间】:2011-07-12 04:36:05
【问题描述】:
我有一个小型 Python 程序,可以从 twitter 流中提取推文以获取关键字。
想要将关键字与收到的推文链接。我怎样才能在 python 中有效地做到这一点。
我可能有超过 200 把钥匙。
例如:
关键字 = "key1,key2,key3"
收到 4 条推文,我想直接链接传入的文本和密钥..
如下图
1)tweets msgs key1 tweets tweets text --> key1
2)tweets msgs key2 tweets tweets text --> key2
3)tweets msgs key3 tweets tweets text --> key3
4)tweets msgs key1 tweets tweets text --> key1
更新:
目前正在使用 for 循环来迭代密钥列表并使用 find 来查看密钥是否存在于推文文本中。但我觉得应该有更好更有效的方法在python中这样做。
for title in title_list:
if tweet_lower.find(title) != -1:
setattr(status, 'title',title)
break
【问题讨论】: