python - Twitter Trending List Printing First Character Instead of First Entry -
i'm having issue can twitter api provide me top 10 list of trending topics in given area, can entirety print, or first character print, not first entry in list.
the following code tried print first entry in list (entry 0) first character each list entry instead (character 0).
from twitter import * access_token = "myaccesstoken" access_token_secret = "myaccesstokensecret" consumer_key = "consumerkey" consumer_secret = "consumersecret" t = twitter(auth=oauth(access_token, access_token_secret, consumer_key, consumer_secret)) results = t.trends.place(_id = 2442047) #i used los angeles woeid location in results: trend in location["trends"]: trendlist = trend["name"] print trendlist[0]
if use simple list this, can python print first entry:
trendlist = ['one', 'two', 'three'] print trendlist[0]
can provide pointer on why behavior different , how 1 entry print trending list?
thank you!
the trends api returns this:
"trends": [ { "events": null, "name": "#ganapuntossi", "promoted_content": null, "query": "%23ganapuntossi", "url": "http://twitter.com/search/?q=%23ganapuntossi" }...]
with second loop iterate through each of above trend "objects".
trendlist = trend["name"]
doesn't list, trend name.
print trendlist[0]
prints out first letter of name.
just print trend["name"] , done.
here's little repl.it https://repl.it/blww/1. printing 10 because looping through them all. if want print first one, can this:
for location in results: print location["trends"][0]['name']
Comments
Post a Comment