Re: Sorting a List of Lists



On Jan 30, 5:55 pm, apoth...@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?

All sorts return None. the sort is in place. Check your list post-
sort.

THN

.



Relevant Pages

  • Re: Append Query Problem
    ... Completed all steps including importing into a blank database. ... It is not an attached table, linked to a back end that is missing. ... If you are still stuck, see if this query returns your linklist table: ... there are 2 internal canonical lists of tables. ...
    (microsoft.public.access.queries)
  • Re: Merge in Word
    ... (here's was missing at certain numbered entries - mine is variable). ... "Peter Jamieson" wrote: ... characters" - that sort of thing. ... work when I didn't use Excel for the database. ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Merge in Word
    ... Peter - that was the problem! ... (here's was missing at certain numbered entries - mine is variable). ... characters" - that sort of thing. ... This has happened when the database is a simple address database in table ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Merge in Word
    ... would be the same data always missing. ... characters" - that sort of thing. ... This has happened when the database is a simple address database in table ... forms to use various portions of the info work just great - and using the ...
    (microsoft.public.word.mailmerge.fields)
  • Re: Sorting a List of Lists
    ... I have two different database tables of events that use different ... schemas. ... this by creating a list of lists that look roughly like this: ... Sort doesn't return a list, ...
    (comp.lang.python)