Re: Sorting a dict by value for template rendering

2008-05-16 Thread Peter Rowell
Variations on this come up all the time. Note that arrays can be sorted. So, create an array of tuples containing the key and the value. Then you can sort the array anyway you please. In the view: # create the array of tuples ordered_dict = [(key, val) for key,val in my_original_dict.items()] #

Sorting a dict by value for template rendering

2008-05-16 Thread bfrederi
I have a dict that looks similar to this: {'com': 'communication', 'tel': 'telephone', 'cel': 'cellphone', 'fax': 'fax machine',} And I want to sort it by value, and render it in a template. I was able to do it, but in a very hacked way. Can anyone show me a better way to do it than my solution.