This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients nilton, rhettinger
Date 2008-12-31.01:48:53
SpamBayes Score 5.253102e-05
Marked as misclassified No
Message-id <>
Am rejecting the patch because it violates the sort equivalence
guarantee (including sort's promise to maintain stability).

If you need the speed and don't care about sort stability, then just use
_heapq.nsmallest() or _heapq.nlargest() directly.

We could complexify the code a bit to achieve some automatic speed-up in
the case of key==None, but my timings don't show much of an improvement:

    if key is None:
        it = izip(iterable, count())                 # decorate
        result = _nsmallest(n, it)
        return map(itemgetter(0), result)            # undecorate
        in1, in2 = tee(iterable)
        it = izip(imap(key, in1), count(), in2)      # decorate
        result = _nsmallest(n, it)
        return map(itemgetter(2), result)            # undecorate
Date User Action Args
2008-12-31 01:49:03rhettingersetrecipients: + rhettinger, nilton
2008-12-31 01:49:03rhettingersetmessageid: <>
2008-12-31 01:48:53rhettingerlinkissue4790 messages
2008-12-31 01:48:53rhettingercreate