Tough sorting problem: or, I'm confusing myself
Raymond Hettinger
python at rcn.com
Wed Apr 14 12:35:18 EDT 2010
> > 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]
:-)
Raymond
More information about the Python-list
mailing list