On Fri, Mar 1, 2013 at 4:04 AM, Tres Seaver <[email protected]> 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
_______________________________________________
Zope-Dev maillist - [email protected]
https://mail.zope.org/mailman/listinfo/zope-dev
** No cross posts or HTML encoding! **
(Related lists -
https://mail.zope.org/mailman/listinfo/zope-announce
https://mail.zope.org/mailman/listinfo/zope )