replace dict contents

Duncan Booth me at privacy.net
Tue Jul 27 04:20:15 EDT 2004


Robin Becker <robin at SPAMREMOVEjessikat.fsnet.co.uk> wrote in 
news:41060AB3.9080600 at jessikat.fsnet.co.uk:

> 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.

The simplest would seem to be

    d1.clear()
    d1.update(d2)

although, this doesn't have the flexibility of a single assignment so you 
can't use it where 'd2' is actually an expression involding d1.



More information about the Python-list mailing list