Dictionary | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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?

15th Apr 2018, 6:09 PM
Kesava N
Kesava N - avatar
3 ответов
+ 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.
15th Apr 2018, 8:33 PM
Emma
+ 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.
16th Apr 2018, 2:04 AM
Emma
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
16th Apr 2018, 1:59 AM
Kesava N
Kesava N - avatar