Quick Python question: How do I access data from a nested list like this:
{'album': [u'Rumours'], 'comment': [u'Track 3'], 'artist': [u'Fleetwood Mac'], 'title': [u'Never Going Back Again'], 'date': [u'1977'], 'genre': [u'Rock'], 'tracknumber': [u'03']}
I tried listname[0][0] but it returns the error:
AttributeError: 'int' object has no attribute 'lower'
So how would I go about doing this?
This is not a list. This is a dictionary.
The dictionary is not ordered, and thus it cannot be accessed through a numeric index*.
You must refer to to it like this:
listname['album']The above will return you a list with one element (which happens to be a list):
[u'Rumours'], to acces a list, you do as usual.So altogether:
Notice that the list could have more elements, so you would refer them like so
[0],[1]etc.Take a look at the docs for more information.
*You can do:
What I meant is that you don’t use zero based indexes, you use keys that can be “whatever you want” and this keys refer to values.