Hi,
I have the following -
messagesReceived = dict.fromkeys(("one","two"), {})
messagesReceived['one']['123'] = 1
messagesReceived['two']['121'] = 2
messagesReceived['two']['124'] = 4
This gives:
{'two': {'121': 2, '123': 1, '124': 4}, 'one': {'121':
2, '123': 1
On 5 Mar 2007 02:22:24 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 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: m
In <[EMAIL PROTECTED]>, bg_ie wrote:
> What am I doing wrong?
`dict.fromkeys()` stores the given object for all keys, so you end up with
the *same* dictionary for 'one' and 'two'.
In [18]: a = dict.fromkeys(("one","two"), {})
In [19]: a
Out[19]: {'two': {}, 'one': {}}
In [20]: a['one']['x'] =
On 5 Mar, 11:45, "Amit Khemka" <[EMAIL PROTECTED]> wrote:
> On 5 Mar 2007 02:22:24 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > Hi,
>
> > I have the following -
>
> > messagesReceived = dict.fromkeys(("one","two"), {})
>
> This will create a dictionary "messagesReceived", with all the
On Mar 5, 11:22 am, [EMAIL PROTECTED] wrote:
> messagesReceived = dict.fromkeys(("one","two"), {})
This creates two references to just *one* instance of empty
dictionary.
I'd do it like:
messagesReceived = dict([(key, {}) for key in ("one","two")])
--
http://mail.python.org/mailman/listinfo/p
"Bart Ogryczak" <[EMAIL PROTECTED]> wrote:
> On Mar 5, 11:22 am, [EMAIL PROTECTED] wrote:
>> messagesReceived = dict.fromkeys(("one","two"), {})
>
> This creates two references to just *one* instance of empty
> dictionary.
> I'd do it like:
> messagesReceived = dict([(key, {}) for key in ("one","