Q: listsort and dictsort - official equivalents?

Neville D NevilleD.python at sgr-a.net
Wed Jun 20 04:45:47 CEST 2007

Choice answer.  It exactly hit the mark.

I implemented "sorted" as follows:

#!/usr/bin/env python
for k in sorted(d,key=lambda k: d[k]): print k,d[k]

b 1
c 2
a 3

I am glad I asked.  Now I know.


On Wed, 2007-06-20 at 02:57 +0200, BJörn Lindqvist wrote:
> You can even sort by the gid:
> for group in sorted(open("/etc/group"), key = lambda x: int(x.split(':')[2])):
>     print group,

Neville D - NZ
note: This document contains Anglo-Saxon Futhorci UTF-8 characters 
from: http://junicode.sourceforge.net/ - eg ᚦᛖ  ᚠᛁᚱᛋᛏ  ᚠᚰᛏ

More information about the Python-list mailing list