Re: dictionary: sorting the values preserving the order

2005-04-01 Thread Terry Reedy
"Rakesh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > This gets a list sorted by the keys. That is all you *can* get (with the list keys being the dict values). > How would I get a revised dictionary sorted by its values. You can't. A dictionary is not sorted. The print orde

Re: dictionary: sorting the values preserving the order

2005-04-01 Thread Luis M. Gonzalez
Another alternative: d1 = {'a':4,'b':5,'c':1,'d':2,'e':3­} il=[(v,k) for k,v in d1.items()] il.sort() -- http://mail.python.org/mailman/listinfo/python-list

Re: dictionary: sorting the values preserving the order

2005-04-01 Thread Ron_Adam
On 31 Mar 2005 22:40:53 -0800, "Rakesh" <[EMAIL PROTECTED]> wrote: >Hi, > For a particular problem of mine, I want to sort pairs >by its value. > >Eg: > >Input: > >A, 4 >B, 5 >C, 1 >D, 2 >E, 3 > >I would like the output to be: > >C >D >E >A >B > >i.e. I would like to get the keys in the sorted o

Re: dictionary: sorting the values preserving the order

2005-04-01 Thread Satchidanand Haridas
Rakesh wrote: Hi, For a particular problem of mine, I want to sort pairs by its value. Eg: Input: A, 4 B, 5 C, 1 D, 2 E, 3 I would like the output to be: C D E A B the following code does that: >>> d1 = {'a':4,'b':5,'c':1,'d':2,'e':3} >>> i1 = [ (d1[i], i) for i in d1.keys() ] >>> i1.sort() >>

Re: dictionary: sorting the values preserving the order

2005-03-31 Thread Vikram
hi, assuming your key-value relationship is one-to-one then as a simple first pass you can simply initialize d1={} and for i in d.keys(): d1[d[i]] = i and pass d1 to your sortedDictValue3 function, no? thanks, Vikram On 31 Mar 2005, Rakesh wrote: > Hi, > For a partic

dictionary: sorting the values preserving the order

2005-03-31 Thread Rakesh
Hi, For a particular problem of mine, I want to sort pairs by its value. Eg: Input: A, 4 B, 5 C, 1 D, 2 E, 3 I would like the output to be: C D E A B i.e. I would like to get the keys in the sorted order of values. I did google around a little bit. One solution to a similar problem sugges