[Tutor] updating a dictionary
Alan Gauld
alan.gauld at btinternet.com
Fri Feb 20 23:30:24 CET 2015
On 20/02/15 17:56, Chris Stinemetz wrote:
> I am getting closer. I think I have figured out the logic. I just have a
> quick question. How do you access key:values in a nested dictionary?
>
> MOL02997_C': [{'2': '0', '7': '0', '8': '0', '9': '0'}]}
>
> say I want to access the key:value 8:0
>
> print dict['MOL02997_C']['8'] doesn't seem to work.
Look closer. The inner dictionary is inside a list [...].
try
print dict['MOL02997_C'][0]['8']
If that works then try to figure out where the extra list
is coming from and eliminate it.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list