Re: Sorting a List of Lists
- From: Létezo <letezo@xxxxx>
- Date: Wed, 31 Jan 2007 01:17:00 +0100
events = [['Event URL as String', 'Event Title as String ', Event Date
as Datetime], ...]
I then thought I'd just go events.sort(lambda x,y: x[2]<y[2]) and call
it a day. That didn't work. But then lamda functions like to be very
simple, maybe object subscripts aren't allowed (even though I didn't
get an error). So I wrote a comparison function that looks much as you
would expect:
Comparision functions must return -1, 0 or 1, not a bool.
You may use a key function instead in this case (requires python 2.4 or newer):
events.sort(key=lambda x: x[2])
Viktor
.
- Follow-Ups:
- Re: Sorting a List of Lists
- From: Paul Rubin
- Re: Sorting a List of Lists
- References:
- Sorting a List of Lists
- From: apotheos
- Sorting a List of Lists
- Prev by Date: Re: Why don't have an object() instance a __dict__ attribute by default?
- Next by Date: Re: how to "free" an object/var ?
- Previous by thread: Re: Sorting a List of Lists
- Next by thread: Re: Sorting a List of Lists
- Index(es):