+ 1
Understanding the syntax of dictionary
I've tried to run following program squares = {1: 1, 2: 4, 3: "error", 4: 16,} squares[8] = 64 squares[3] = 9 print(squares) In my IDLE I'm getting output : {1: 1, 2: 4, 3: 9, 4: 16, 8: 64} which makes sense but in your result window, I'm seeing result : {8: 64, 1: 1, 2: 4, 3: 9, 4: 16} which one is right one ?
1 Answer
0
Dictionary keys are not ordered( opposite to List). so every time you will get different output unless you force to print one by one using keys.sort().