Q: listsort and dictsort - official equivalents?
Neville D
NevilleD.python at sgr-a.net
Tue Jun 19 22:45:47 EDT 2007
Choice answer. It exactly hit the mark.
I implemented "sorted" as follows:
#!/usr/bin/env python
d=dict(zip("cba",(2,1,3)))
for k in sorted(d,key=lambda k: d[k]): print k,d[k]
Output:
b 1
c 2
a 3
I am glad I asked. Now I know.
Thanᚷ
NevilleDNZ
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