[Tutor] Sort dictionaries

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Nov 15 22:28:25 CET 2004

On Mon, 15 Nov 2004, David Holland wrote:

> Is there a built command to sort a dictionary keys or values by their
> length or do I have to write a function to do it myself ?

Hi David,

You might find the Sorting HOWTO helpful; here's a link to it:


Dictionaries themselves can't be sorted, but their keys and values can be.

You might need to define your own comparison function. The HOWTO link
above shows how to get the sort to work by other criteria.

If you have more questions, please feel free to ask!

More information about the Tutor mailing list