Is numeric keys of Python's dictionary automatically sorted?

Matthias Julius jnews at julius-net.net
Thu Mar 8 12:47:03 EST 2007


"John" <rds1226 at sh163.net> writes:

> 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 wonder why nobody has suggested the use of a list:

redix = [[] for i in range(256)]

Matthias



More information about the Python-list mailing list