[Tutor] calculating a sort key and operator.attrgetter()

Vincent Davis vincent at vincentdavis.net
Wed Jul 1 05:39:35 CEST 2009

I have a class with an attribute which is a list "rank_list" this is a list
of instances f another class that has attributes "quality, is_observed"
if I want to sort the list by the attribute "quality" I can just use,
But I want to sort like this.
self.rank_list.sort(key=(operator.attrgetter('quality') *
operator.attrgetter('is_observed') * self.does_observe))
Will this work or is there a better way?

Vincent Davis
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090630/9edadce2/attachment.htm>

More information about the Tutor mailing list