Nested Dictionaries
Ben Cornett
Tue May 23 17:15:22 EDT 2000
On Thu, May 18, 2000 at 03:42:04PM -0400, Chris Lada wrote:
> Is there some where of directly accessing information in a dictionary which
> occurs as part of another dictionary i.e.:
>
> inner = {'city':'This City','state':'This State'}
> outer = {'12345':inner}
>
> In order to access the 'city' information in the 12345 dictionary entry, I
> do the following:
>
> temp = outer['12345'] # yields the outer dictionary entry with the key
> '12345'
>
> tempCity = temp['city'] # yields the city value of the inner dictionary of
> the
> # outer dictionary entry with the key
> '12345'
>
> Is there an easier or more direct way of doing this ?
>
> Thanks,
> Chris
>
>
Hi,
You could certainly drop the first temporary and simply write:
tempCity = outer['12345']['city']
Cheers,
Ben
More information about the Python-list
mailing list