[Tutor] simple report writing?

Kent Johnson kent37 at tds.net
Mon Nov 7 20:30:02 CET 2005


CPIM Ronin wrote:
> I have a list (x_list) of class data. How do I sort that list by a 
> selected variable common to all members of the list?
> 
> x_list.sort(key=x_list.v_name) # doesn't work becuase x_list can't see 
> the individual items.

Use
import operator
x_list.sort(key=operator.attrgetter('v_name'))

Kent

-- 
http://www.kentsjohnson.com



More information about the Tutor mailing list