Python - iterate over JSON results -
in order energy
values, trying iterate on json
result:
[{u'track_href': u'https://api.spotify.com/v1/tracks/7603o589huckpbielnukgu', u'analysis_url': u'https://api.spotify.com/v1/audio-analysis/7603o589huckpbielnukgu', u'energy': 0.526, u'liveness': 0.0966, u'tempo': 92.979, u'speechiness': 0.103, u'uri': u'spotify:track:7603o589huckpbielnukgu', u'acousticness': 0.176, u'instrumentalness': 0.527, u'time_signature': 4, u'danceability': 0.635, u'key': 1, u'duration_ms': 172497, u'loudness': -8.073, u'valence': 0.267, u'type': u'audio_features', u'id': u'7603o589huckpbielnukgu', u'mode': 1},...}]
i'm using list comprehension:
[x['energy'] x in features]
but i'm getting following error:
print ([x['energy'] x in features]) typeerror: 'nonetype' object has no attribute '__getitem__'
what doing wrong here?
it because within json array, @ place instead of dictionary none
value present. may eliminate via:
[x['energy'] x in features if x]
Comments
Post a Comment