[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: Nasty gotcha/bug in heapq.nlargest/nsmallest
From: Raymond Hettinger <python () rcn ! com>
Date: 2008-05-31 3:46:07
Message-ID: 8c937dcb-082f-4182-be44-429fec31a8b9 () z24g2000prf ! googlegroups ! com
[Download RAW message or body]
On May 15, 12:06 am, Peter Otten <__pete...@web.de> wrote:
> According
> to my ad hoc test you need <, <=, and == for nlargest()/nsmallest() to
> work:
In Py2.6 and after, you only need < and ==. I replaced the LE tests
with LT to match list.sort() and bisect.bisect(). The == arises
because nlargest/nsmallest compare decorated tuples. Tuple comparison
always starts with equality tests to find the first unequal element
and then switches back to testing whichever inequality test was
requested.
Raymond
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic