0
dict_c = {1: {2: 3}, 4: 5}

dict_d = dict_c.copy()

dict_d[4] = 9

dict_d[1][2] = 9

print(dict_c)

Answer:

{1: {2: 9}, 4: 5}

Why is the output not {1: {2: 9}, 4: 9} instead? I just started coding and one of the practice I came across this question, thank you so much for the help

Mechanic Pig
  • 6,756
  • 3
  • 10
  • 31
Junhao
  • 3
  • 1

1 Answers1

0

It is your printing the wrong one

In [106]: dict_c = {1: {2: 3}, 4: 5}
     ...:
     ...: dict_d = dict_c.copy()
     ...:
     ...: dict_d[4] = 9
     ...:
     ...: dict_d[1][2] = 9
     ...:
     ...: print(dict_c)
     ...: print(dict_d)
{1: {2: 9}, 4: 5}
{1: {2: 9}, 4: 9}
tokentarts
  • 34
  • 2