[Tutor] Sorting on different fields

the New me newgat11 at yahoo.com
Sun Dec 7 06:47:16 CET 2008


Thanks Kent:

Is there an example for sorting on 2 or 3 fields,

I saw this page http://personalpages.tds.net/~kent37/kk/00007.html#e7sorting-on-multiple-keys

It just gives a cursory note:
To sort a list of items with primary and secondary sort keys, provide a key function that returns a tuple of keys. In Python 2.5, both itemgetter() and attrgetter() accept multiple arguments and return functions that create the correct tuples.

that does nt do it for me,
Python is supposed to be programmer user freindly,
is there a straightforward example?

like in SQL one can easily say 
Order by field1 field2 field3

when it comes to sort, books on python give this gimmiky phrase: you can do easily using ...
but no example!!

is one supposed to make a class with attr and item and how are these constructed from the fields being given, and how is the whole row sorted by the field(s) that are part of the row.
the books dont explain that, 
how are the rows sorted, by field1 say, then by field2, etc,
how is one supposed to make the class, so that these things are attributes in the rows.

am sure there must be something on the internet, 
but again it is not satisfactory, 
or the people writing the examples are so smart or everybody else is dum?

Thanks all




--- On Sat, 12/6/08, Kent Johnson <kent37 at tds.net> wrote:

> From: Kent Johnson <kent37 at tds.net>
> Subject: Re: [Tutor] Sorting on different fields
> To: newgat11 at yahoo.com
> Cc: tutor at python.org
> Date: Saturday, December 6, 2008, 1:31 PM
> On Sat, Dec 6, 2008 at 1:01 PM, the New me
> <newgat11 at yahoo.com> wrote:
> >
> >
> > I would like to be able to sort a list of rows,
> > each row has (say 4) fields to sort on,
> >
> > primary key to sort on first, then the second one and
> so on,
> >
> > any suggestions and where to look (may be),
> 
> http://personalpages.tds.net/~kent37/kk/00007.html#e7sorting-on-multiple-keys
> 
> Kent


      


More information about the Tutor mailing list