Re: Dict Copy & Compare
- From: Steven D'Aprano <steve@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 30 Apr 2007 20:08:51 +1000
On Mon, 30 Apr 2007 09:40:53 +0100, Tim Golden wrote:
Robert Rawlins - Think Blue wrote:
I'm looking for a little advice on dicts, firstly I need to learn how to
copy a dict, I suppose I could just something like.
Self.newdict = self.olddict
But I fear that this only creates a reference rather than an actual copy,
this means that as soon as I clear out the old one, the new one will
effectively be empty. What's the best way to ACTUALY copy a dict into a new
variable?
Unless you have specialised needs, you can just say:
d2 = dict (d1)
Or you can say
d2 = d1.copy()
--
Steven D'Aprano
.
- References:
- Re: Dict Copy & Compare
- From: Tim Golden
- Re: Dict Copy & Compare
- Prev by Date: Re: How do I parse a string to a tuple??
- Next by Date: Re: How do I parse a string to a tuple??
- Previous by thread: Re: Dict Copy & Compare
- Next by thread: RE: Dict Copy & Compare
- Index(es):