On Aug 3, 1:36 pm, Raymond Hettinger wrote:
> [Joshua Bronson]:
>
> > According tohttp://docs.python.org/library/heapq.html, Python 2.5
> > added an optional "key" argument to heapq.nsmallest and
> > heapq.nlargest. I could never understand why they didn't also add a
> > "key" argument to the othe
[Joshua Bronson]:
> According tohttp://docs.python.org/library/heapq.html, Python 2.5
> added an optional "key" argument to heapq.nsmallest and
> heapq.nlargest. I could never understand why they didn't also add a
> "key" argument to the other relevant functions (heapify, heappush,
> etc).
The pro
[Duncan Booth]
> The documentation doesn't say anything directly about stability, but the
> implementation is actually stable. You can probably assume it must be at
> least for nlargest and nsmallest otherwise the stated equivalence wouldn't
> hold:
>
> e.g. nsmallest documentation says:
>
>
"Gabriel Genellina" wrote:
> Ok, it's not strictly the same, but usually it doesn't hurt. The heaqp
> module doesn't promise anything about equal elements: it may keep the
> original order, rearrange them at will, reverse them, whatever.
The documentation doesn't say anything directly about st
En Fri, 31 Jul 2009 16:38:01 -0300, Joshua Bronson
escribió:
On Jul 31, 2:02 pm, Jonathan Gardner
wrote:
On Jul 31, 10:44 am, Joshua Bronson wrote:
> Say I want to maintain a heap of (x, y) pairs sorted only by
> first coordinate. Without being able to pass key=itemgetter(0), won't
> hea
On Jul 31, 2:02 pm, Jonathan Gardner
wrote:
> On Jul 31, 10:44 am, Joshua Bronson wrote:
>
> > Say I want to maintain a heap of (x, y) pairs sorted only by
> > first coordinate. Without being able to pass key=itemgetter(0), won't
> > heapifying a list of such pairs unnecessarily compare both
> >
On Jul 31, 10:44 am, Joshua Bronson wrote:
> Say I want to maintain a heap of (x, y) pairs sorted only by
> first coordinate. Without being able to pass key=itemgetter(0), won't
> heapifying a list of such pairs unnecessarily compare both
> coordinates?
It will compare the second value only if th
According to http://docs.python.org/library/heapq.html, Python 2.5
added an optional "key" argument to heapq.nsmallest and
heapq.nlargest. I could never understand why they didn't also add a
"key" argument to the other relevant functions (heapify, heappush,
etc). Say I want to maintain a heap of (x