[Tutor] Sort dictionaries

David Holland davholla2002 at yahoo.co.uk
Mon Nov 15 22:35:15 CET 2004


Thanks a lot that is very helpful.

 --- Danny Yoo <dyoo at hkn.eecs.berkeley.edu> wrote: 
> 
> 
> 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:
> 
>    
> http://www.amk.ca/python/howto/sorting/sorting.html
> 
> 
> 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!
> 
>  


		
___________________________________________________________ 
Moving house? Beach bar in Thailand? New Wardrobe? Win £10k with Yahoo! Mail to make your dream a reality. 
Get Yahoo! Mail www.yahoo.co.uk/10k


More information about the Tutor mailing list