"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
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
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
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()
>>
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
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