Twitter Stream response for key words
Update:
Currently am using for loop to iterate the key list and use find to see if the key is present in the tweet text.But i feel there should be better and efficient way of doing this in python. for title in title_list:
if tweet_lower.find(title) != -1:
setattr(status, 'title',title)
break
Use defaultdict
from Python's collection module.
In [1]: from collections import defaultdict
In [2]: tweet_keyword_storage = defaultdict(list)
In [3]: tweet_keyword_storage['key1'].append('tweets msgs key1 tweets tweets text')
In [4]: tweet_keyword_storage['key2'].append('tweets msgs key2 tweets tweets text')
In [5]: tweet_keyword_storage['key3'].append('tweets msgs key3 tweets tweets text')
In [6]: tweet_keyword_storage['key1'].append('tweets msgs key1 tweets tweets text')
In [7]: print tweet_keyword_storage
defaultdict(<type 'list'>, {'key3': ['tweets msgs key3 tweets tweets text'], 'key2': ['tweets msgs key2 tweets tweets text'], 'key1': ['tweets msgs key1 tweets tweets text', 'tweets msgs key1 tweets tweets text']})
精彩评论