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 <1230688143.73.0.374534476692.issue4790@psf.upfronthosting.co.za>
In-reply-to
Content
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
    else:
        in1, in2 = tee(iterable)
        it = izip(imap(key, in1), count(), in2)      # decorate
        result = _nsmallest(n, it)
        return map(itemgetter(2), result)            # undecorate
History
Date User Action Args
2008-12-31 01:49:03rhettingersetrecipients: + rhettinger, nilton
2008-12-31 01:49:03rhettingersetmessageid: <1230688143.73.0.374534476692.issue4790@psf.upfronthosting.co.za>
2008-12-31 01:48:53rhettingerlinkissue4790 messages
2008-12-31 01:48:53rhettingercreate