I'm trying to add new key-key-value registers to a python dictionary where key and key will be taken as variable names in a loop, here is my code:
def harvestTrendingTopicTweets(twitterAPI, trendingTopics, n):
statuses = {}
for category in trendingTopics:
for trend in trendingTopics[category]:
results = twitterAPI.search.tweets(q=trend, count=n, lang='es')
statuses[category][trend] = results['statuses']
return statuses
trendingTopics is a dictionary generated after this json
{
"General": ["EPN","Peña Nieto", "México","PresidenciaMX"],
"Acciones politicas": ["Reforma Fiscal", "Reforma Energética"]
}
So far I'm getting KeyError: u'Acciones politicas' error message as such key doesn't exist. How can I accomplish this?