Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17142

Using methodcaller in a list sort - any examples anywhere?

From tinnews@isbd.co.uk
Newsgroups comp.lang.python
Subject Using methodcaller in a list sort - any examples anywhere?
Date 2011-12-13 15:48 +0000
Message-ID <hm8kr8-uge.ln1@chris.zbmc.eu> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Using methodcaller in a list sort - any examples anywhere? tinnews@isbd.co.uk - 2011-12-13 15:48 +0000
  Re: Using methodcaller in a list sort - any examples anywhere? Peter Otten <__peter__@web.de> - 2011-12-13 17:13 +0100
    Re: Using methodcaller in a list sort - any examples anywhere? tinnews@isbd.co.uk - 2011-12-13 16:48 +0000
  Re: Using methodcaller in a list sort - any examples anywhere? Tim Chase <python.list@tim.thechases.com> - 2011-12-13 10:08 -0600

csiph-web