[Zope-dev] ZTK 2.0: Deprecate zope.sequencesort

Lennart Regebro regebro at gmail.com
Fri Mar 1 08:41:50 UTC 2013


On Fri, Mar 1, 2013 at 4:04 AM, Tres Seaver <tseaver at palladion.com> wrote:
> Assuming an unsorted list of news stories, how would you use sorted to
> get them ordered by category (ascending) + publication date (descending)?

This is the easiest, most obvious way:

     sorted(sorted(news_stories, lambda x: x.publication_date,
reverse=True), lambda x: x.category)

And yes, I have made performance analysis, and it is often faster two
do two sorts than trying to compute a complex key.

> If you spend more than a minute on it (e.g., trying to come up with a
> bug-free way to compute "negative dates") you've proved my mpoint. :)

I haven't got a clue what "negative dates" are, unless you mean BC.
But the above works (unless I got ascending and descending mixed up as
usual).

//Lennart


More information about the Zope-Dev mailing list