I am new to python. When I was playing around with the code, I found this.
Source Code:
dic = {}
mem_dic = {}
def set_op(ind, data):
global dic, mem_dic
key, value = data.split()
dic[key] = int(value)
mem_dic[ind] = dic
print(ind, "====", mem_dic)
set_op(0, 'aaa 1')
set_op(1, 'bbb 2')
Expected Output:
0===={0:{'aaa':1}}
1===={0:{'aaa':1},1:{'aaa':1,'bbb':1}}
Actual Output:
0===={0:{'aaa':1,'bbb':1}}
1===={0:{'aaa':1,'bbb':1}}
Could anyone please explain the reason for this behavior. And what changes should I incorporate to get the expected output.