Sort dictionary data

Peter Hansen peter at engcorp.com
Mon May 20 15:05:32 EDT 2002


> Marcus Laranjeira wrote:
> 
> All,
> 
>    I have a dictionary that I need to be sorted. the current structure is :
> 
> dic { 'aaa', 1, 'bbb', 1, 'ccc', 3, 'ddd', 2, 'eee', 1}
> 
> and I need this to be sorted and the final dictionary should be:
> 
> dic { 'aaa', 1, 'bbb', 1, 'eee', 1, 'ddd', 2, 'ccc', 3}
> 
> does anyone knows how can this be done ? Is there any ready module to do such sorting ?

Those are not dictionaries, unless you mean { 'aaa' : 1, 'bbb' : 1, etc....

And in any event, dictionaries are unsorted.  Search for something
like 'python "sorted dictionary"' in Google to find some non-standard
implementations that might help you:

http://www.google.ca/search?hl=en&q=python+%22sorted+dictionary%22

There have been past discussions of this.

-Peter



More information about the Python-list mailing list