Message78587
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 |
|
Date |
User |
Action |
Args |
2008-12-31 01:49:03 | rhettinger | set | recipients:
+ rhettinger, nilton |
2008-12-31 01:49:03 | rhettinger | set | messageid: <1230688143.73.0.374534476692.issue4790@psf.upfronthosting.co.za> |
2008-12-31 01:48:53 | rhettinger | link | issue4790 messages |
2008-12-31 01:48:53 | rhettinger | create | |
|