Reputation: 970
I want to create a copy of a existing dict
b = {'name':'someone'}
copy_b = b
if do this, changes made in copy_b will affect b, how can I make copy_b unique to b?
Thanks,
Upvotes: 2
Views: 52
Reputation: 11070
use dict()
>>>a = {1:1}
>>>b = dict(a)
>>>b[2] = 2
>>>a
{1:1}
This will do good
Upvotes: 1
Reputation: 114038
from copy import deepcopy
copy_b = deepcopy(d)
should work ... I would think at least
if its just a simple dictionary like above
copy_b = dict(d)
Upvotes: 1