Well, this is what Kushal said, and I agree completely.
I wanted to sort a dictionary by value. I asked Kushal.
He said, "I don't know. You can sort it by key. Maybe you have to do manually!"
I went ahead and googled...
And this is how we do it:
alist = sorted(alist.iteritems(), key=lambda (k,v): (v,k))
I wanted to sort a dictionary by value. I asked Kushal.
He said, "I don't know. You can sort it by key. Maybe you have to do manually!"
I went ahead and googled...
And this is how we do it:
alist = sorted(alist.iteritems(), key=lambda (k,v): (v,k))
2 comments:
what is the usage context of such a feature?
you can always sort a dictionary by key, I wanted to sort it by values.
Post a Comment