Is numeric keys of Python's dictionary automatically sorted?
John
rds1226 at sh163.net
Wed Mar 7 15:18:10 EST 2007
I am coding a radix sort in python and I think that Python's dictionary may
be a choice for bucket.
The only problem is that dictionary is a mapping without order. But I just
found that if the keys are numeric, the keys themselves are ordered in the
dictionary.
part of my code is like this:
radix={}
for i in range(256):
radix[i]=[]
I checked and found that it is ordered like: {1:[], 2:[], 3[],...}
So I can just print out the contents of the dictionary in the desired order
without additional code.
I also tried adding new numeric keys and found that the dictionary's keys
are still ordered.
However, I am not sure whether it is always like this. Can anybody confirm
my finding?
More information about the Python-list
mailing list