Python set a dict to default dict

43 Views Asked by At

I have a dict

default_x = {'a' : 1, 'b' : 1}

Later I am updating this dict based on my problem.

But whenever when I am calling this default_x.

I want it to it's default value not it's updated value. Any guidance on this. example:

def func1(key, val):
    x = default_x
    x[key] = val

temp = func1('a',2)
output is {'a' : 2, 'b' : 1}
Now if i call
temp = func1('b',2)
output is {'a' : 2, 'b' : 2}

I want my output for second execution as
output is {'a' : 1, 'b' : 2}
0

There are 0 best solutions below