[Zope] sort in python script dynamically?

Paul Winkler pw_lists at slinkp.com
Tue Jan 13 12:17:06 EST 2004


On Tue, Jan 13, 2004 at 12:47:37AM -0800, Alec Mitchell wrote:
> in this case it would be:
> 
> def sort_by_field(list, f):
> 	decorated = [(getattr(obj, f), obj) for obj in list]
> 	decorated.sort()
> 	return [a[1] for a in decorated]

That's fine, but dont't get in the habit of using "list"
as a variable name. There is a python built-in with the
same name! Hiding builtins is likely to be cause bugs 
sooner or later.

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's BASTARD-HUGGER!
(random hero from isometric.spaceninja.com)



More information about the Zope mailing list