Tough sorting problem: or, I'm confusing myself
Lie Ryan
lie.1296 at gmail.com
Fri Apr 16 08:17:00 EDT 2010
On 04/15/10 02:03, Paul Rubin wrote:
> 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]
or sorted(iterable)[-2:]
More information about the Python-list
mailing list