Dictionary of Dictionaries

bg_ie at yahoo.com bg_ie at yahoo.com
Mon Mar 5 06:09:10 EST 2007


On 5 Mar, 11:45, "Amit Khemka" <khemkaa... at gmail.com> wrote:
> On 5 Mar 2007 02:22:24 -0800, b... at yahoo.com <b... at yahoo.com> wrote:
>
> > Hi,
>
> > I have the following -
>
> > messagesReceived = dict.fromkeys(("one","two"), {})
>
> This will create a dictionary "messagesReceived", with all the keys
> referring to *same instance* of the (empty) dictionary.
> (   try: messagesReceived = dict( [(k,{}) for k in ('one', 'two') ] )   )
>
>
>
> > messagesReceived['one']['123'] = 11111
> > messagesReceived['two']['121'] = 22222
> > messagesReceived['two']['124'] = 43333
>
> > This gives:
>
> > {'two': {'121': 22222, '123': 11111, '124': 43333}, 'one': {'121':
> > 22222, '123': 11111, '124': 43333}}
>
> And hence the results !
>
> HTH,
>
> --
> ----
> Amit Khemka -- onyomo.com
> Home Page:www.cse.iitd.ernet.in/~csd00377
> Endless the world's turn, endless the sun's Spinning, Endless the quest;
> I turn again, back to my own beginning, And here, find rest.

Thanks for your help!




More information about the Python-list mailing list