3

Trying to access just the 'name' part of trends for Toronto. so far I have this but it is giving me errors:

toronto = t.get_place_trends(id=4118)

trend_array = []
for trend in toronto.trends.name:
    trend_array.append(trend) 
    print trend_array
    print trend

Thats after auth and returns the entire list of objects forced into an array (which cant be accessed with indexing for some reason) and as a list.

applewood
  • 391
  • 2
  • 11
  • What error are you getting? Do you know what data type the return value is? You can add a print type(toronto) after the first line to confirm. – ChrisProsser Jun 25 '13 at 17:35
  • `but it is giving me errors`, would you be kind enough to let us know the errors? You cannot solve if you don't know the problem. – Bibhas Debnath Jun 25 '13 at 18:23

1 Answers1

3

Wow, that's really strange that toronto returns a list that has to be accessed by indices.

Here is the code that you'll need:

toronto = t.get_place_trends(id=4118)
trend_array = []

if toronto:
    for trend in toronto[0].get('trends', []):
        trend_array.append(trend['name'])
        print trend_array
        print trend
Mike Helmick
  • 313
  • 1
  • 5
  • Perfect thanks to get the output I wanted I used the last line print trend['name'] but that is pretty straight forward. Such a strange way to access the information. – applewood Jun 26 '13 at 14:37