replace dict contents
Satchidanand Haridas
sharidas at zeomega.com
Tue Jul 27 08:54:21 EDT 2004
Tim Jarman wrote:
>
> On 27 Jul 2004, at 08:56, Robin Becker wrote:
>
>> Is there a simple way to replace the contents of a dictionary
>> entirely with those of another.
>>
>> for lists we can do
>>
>> L1[:] = L2
>>
>> but there doesn't seem to be an equivalent for dicts.
>> --
>> Robin Becker
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>
> How about:
>
> >>> d1 = { "spam" : "eggs" }
> >>> d2 = { "gumby" : "my brain hurts!"}
> >>> d1 is d2
> False
> >>> d1 = dict(d2)
> >>> d1
> {'gumby': 'my brain hurts!'}
> >>> d1 is d2
> False
>
> HTH
>
> Tim J
Quoting from Python Language Reference:
"The operators is and is not test for object identity: |x is y| is true
if and only if x and y are the same object. |x is not y| yields the
inverse truth value."
d1 and d2 are not the same objects. They are two different objects
having the same value. Hence using the 'is' operator returns false.
On the other hand,
>>>d3 = d2
>>>d3 is d2
True
Regards,
Satchit
----
Satchidanand Haridas (sharidas at zeomega dot com)
ZeOmega (www.zeomega.com)
Open Minds' Open Solutions
#20,Rajalakshmi Plaza,
South End Road,
Basavanagudi,
Bangalore-560 004, India
More information about the Python-list
mailing list