On 9/23/14 4:53 PM, Denis McMahon wrote:
from string import *

You aren't using any names from string, so you can skip this line.


x={'f1':1,'f2':2,'f3':3}
y = [ (a,x[a]) for a in x.keys() ]
y.sort( cmp=lambda a,b: cmp(a[0],b[0]) )

This is more easily done as:

    y = sorted(x.items())

.items() returns a sequence of (key, value) pairs, and tuples are sorted lexicographically, so the first elements are compared first, then the second, etc.

--
Ned Batchelder, http://nedbatchelder.com

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to