Re: Sorting a List of Lists



apotheos@xxxxxxxxx wrote:
I can't seem to get this nailed down and I thought I'd toss it out
there as, by gosh, its got to be something simple I'm missing.

I have two different database tables of events that use different
schemas. I am using python to collate these records for display. I do
this by creating a list of lists that look roughly like this:

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:

def date_compare(list1,
list2):
x = list1[2]
y = list2[2]
if
x>y:
return
1
elif
x==y:
return
0
else: #
x<y
return -1

But as before sorting with this function returns None.

What have I overlooked?

Sort doesn't return a list, it sorts in place. None is
the result code (if you will) of the sort completion.

-Larry
.



Relevant Pages

  • Re: Sorting a List of Lists
    ... there as, by gosh, its got to be something simple I'm missing. ... I have two different database tables of events that use different ... this by creating a list of lists that look roughly like this: ... the sort is in place. ...
    (comp.lang.python)
  • Re: Getting a list of list permissions for WSS
    ... this on a backup copy of the database so you're not hitting the live DB. ... Now when you run the script and refresh the SPS Event List which this ... my departmental Event Lists roll-up flawlessly to a single Portal list. ...
    (microsoft.public.sharepoint.portalserver)
  • Panic, a strange behavior of lisp program
    ... when SORT is called with a parameter that includes some that ... No actually although CLtL ... this apparent mistake in conversion from CLtL to ANSI-CL. ... Web page that lists all such "obvious" mistakes. ...
    (comp.lang.lisp)
  • Re: The Sorrows of Record Cataloguing
    ... but the database ... needed was a list so that I wouldn't buy records or CDs over again. ... to see on the shelves and were in alpha-order by composer. ... recordings, there is an entirely different set of lists -- five lists, ...
    (rec.music.classical.recordings)
  • Re: Primary Key not sorted
    ... Are you willing to rely on any "natural" sort of records? ... > though the Company field is the Primary Key but if I ... When I Compact and Repair the database it ...
    (microsoft.public.access.tablesdbdesign)