Sorting a List of Lists
larry.bates at websafe.com
Wed Jan 31 01:32:02 CET 2007
apotheos at gmail.com 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<y) 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,
> x = list1
> y = list2
> else: #
> 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.
More information about the Python-list