Question

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.

Was it helpful?

Solution

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top