0

I'm using a parent dict from which to generate a child, here's the problem :

child = parent

This obviously means editing the child will also edit the parent, they're just different names for the same object. I want them to be separate objects

child=parent.copy()
child=dict(parent)

Both of these solve the problem only for top level key:value pairs. Any value that's a nested dict is still shared between child and parent

child=json.loads(json.dumps(parent))

This is the only solution I've found that works but it feels so wrong ! Does anyone know a better/simpler way ?

ice-wind
  • 690
  • 4
  • 20

0 Answers0