Using methodcaller in a list sort - any examples anywhere?

tinnews at isbd.co.uk tinnews at isbd.co.uk
Tue Dec 13 10:48:01 EST 2011


I want to sort a list of 'things' (they're fairly complex objects) by
the contents of one of the fields I can extract from the 'things'
using a Python function.

So I have a list L which is a list of objects of some sort.  I can
output the contents of a field in the list as follows:-

    for k in L:
        print k.get_property('family-name')

How can I sort the list first?  As I said it seems like a methodcaller
is the answer but I don't see how.  I want to sort the list of objects
not just produce a sorted list of names.

-- 
Chris Green



More information about the Python-list mailing list