+ 1
Dictionary
squares = {1: 1, 2: 4, 3: "error", 4: 16,} squares[8] = 64 squares[3] = 9 print(squares) the out put is contains 8:64 in begining why?
3 Antworten
+ 2
Dictionaries are unordered key / value pairs, so it's not worth Python keeping them ordered, as that would take more processing time.
You can still access the dictionary items you want using the relevant keys for those items.
+ 2
Whether it's ordered or not is irrelevant. The order is arbitrary based on the implementation inside python, which is hidden.
You'd have to look at python's code to find out why it chooses a particular order for dictionaries.
0
if I put one more row of code like squares[7]=49 in 4 line of code then the out is like 7:49, 8:64 is at the end then why here it is ordered