Python - Looping through a multidimensional dictionary -
this question has answer here:
- how loop dict in {} using python 2 answers
if explain think doing, hope can explain going wrong.
i have following dictionary:
ls = [{ 'the wolf gift (13)': { 'cover': 'v:\\books\\anne rice\\the wolf gift (13)\\cover.jpg', 'author': 'anne rice', 'year': '1988' }, 'mummy (14)': { 'cover': 'v:\\books\\anne rice\\mummy (14)\\cover.jpg', 'author': 'anne rice', 'year': '1989' }, }]
first of above multidimensional dictionary? want make sure talking right thing. secondly, how loop through retrieve information @ various levels. dictionary dynamically populated not know keys before hand.
i have tried for book in ls
, book['cover']
etc.. doesn't seem work. need book name, , additional info each book (cover etc...). pretty new python. come php , using arrays bread , butter, python killing me....
thanks
it's list containing single dictionary. can like:
>>> books = ls[0] >>> book, details in books.iteritems(): print book,'-->', details['cover'] ... mummy (14) --> v:\books\anne rice\mummy (14)\cover.jpg wolf gift (13) --> v:\books\anne rice\the wolf gift (13)\cover.jpg
Comments
Post a Comment