replace dict contents
Peter Otten
__peter__ at web.de
Tue Jul 27 08:49:45 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
> How about:
>
> >>> d1 = { "spam" : "eggs" }
> >>> d2 = { "gumby" : "my brain hurts!"}
> >>> d1 is d2
> False
> >>> d1 = dict(d2)
This rebinds the name d1 to a copy of d2 and will not affect other
references to the original d1.
Peter
More information about the Python-list
mailing list