Tough sorting problem: or, I'm confusing myself

Paul Rubin no.email at nospam.invalid
Wed Apr 14 18:03:02 CEST 2010


Raymond Hettinger <python at rcn.com> writes:
> Not sure what the readability issue is.  The phrase "nlargest(2,
> iterable)" does exactly what it says, finds the 2 largest elements
> from an iterable.  That makes the programmer's intent more clear than
> the slower, but semanticly equivalent form:  sorted(iterable)[:2].

I think you meant

   sorted(iterable, reverse=True)[:2]



More information about the Python-list mailing list