Why does adding things to a dictionary work like this?


#1

So, I added pairs to my dictionary, but I was just wondering why they ended up in the order they were? It’s not alphabetical by the keys, or numerical by the ‘destinations’.

Pic:


#2

Hi @jbatchelor1,

Python 2.x dictionaries are unordered, so if you want to process the items in a particular order, you would have to use a list or other mechanism, and possibly a loop, for presenting the keys in the desired order.


#3

Is this a bot reply?

Why does is go in that order - I don’t care about making it in the order I want (here)


#4

No.

Unlike Python lists, which use numbered indexing, Python dictionaries use hash tables to manage the storage and retrieval of items. That is an efficient mechanism for handling keys of a wide variety of types. For lots of details about this, see Wikipedia: Hash table.


#5

Thanks c: 1234567890


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.