[Tutor] updating a dictionary

Chris Stinemetz chrisstinemetz at gmail.com
Fri Feb 20 18:56:53 CET 2015


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.

Thanks in advance.

On Thu, Feb 19, 2015 at 5:10 PM, Alan Gauld <alan.gauld at btinternet.com>
wrote:

> On 19/02/15 22:50, Emile van Sebille wrote:
>
>       if cell.endswith(suffix, 14, 16) is False:
>>>
>>
>> ... so they'll never end with numeric values.  Further, "".endswith()
>> accepts only one argument so you ought to get an error on this line.
>>
>
> Sorry Emile, The OP is correct.
>
> ######################
> >>> help(''.endswith)
> endswith(...) method of builtins.str instance
>     S.endswith(suffix[, start[, end]]) -> bool
>
>     Return True if S ends with the specified suffix, False otherwise.
>     With optional start, test S beginning at that position.
>     With optional end, stop comparing S at that position.
>     suffix can also be a tuple of strings to try.
> #######################
>
> The tuple is the set of suffices and the numbers are the
> start/end points. Its not often seen like that but the
> OP is quite correct.
>
>
> The test against False is unusual it woyuld normally look like
>
>      if not cell.endswith(suffix, 14, 16):
>
> but that is just a style issue.
>
>
> --
> 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
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>


More information about the Tutor mailing list