Newbie: sort list of dictionaries

Wade Leftwich wade at lightlink.com
Tue Dec 30 18:39:47 EST 2003


D'oh! That sortlist() function was needlessly clever. This is nicer:

>>> def sortlist(L, decorator=None):
... 	if decorator is None:
... 		L.sort()
... 		return
... 	newL = [(decorator(x), x) for x in L]
... 	newL.sort()
... 	L[:] = [y for (x,y) in newL]




More information about the Python-list mailing list