Re: Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-30 Thread Raymond Hettinger
On May 15, 12:06 am, Peter Otten <[EMAIL PROTECTED]> 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 nla

Re: Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-15 Thread George Sakkis
On May 15, 3:06 am, Peter Otten <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > I spent several hours debugging some bogus data results that turned > > out to be caused by the fact that heapq.nlargest doesn't respect rich > > comparisons: > > > import heapq > > import random > > >

Re: Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-15 Thread Peter Otten
George Sakkis wrote: > I spent several hours debugging some bogus data results that turned > out to be caused by the fact that heapq.nlargest doesn't respect rich > comparisons: > > import heapq > import random > > class X(object): > def __init__(self, x): self.x=x >

Re: Nasty gotcha/bug in heapq.nlargest/nsmallest

2008-05-14 Thread Gabriel Genellina
En Wed, 14 May 2008 23:47:56 -0300, George Sakkis <[EMAIL PROTECTED]> escribió: > I spent several hours debugging some bogus data results that turned > out to be caused by the fact that heapq.nlargest doesn't respect rich > comparisons: > > import heapq > import random > > class X(obje