[issue6614] heapq.nsmallest and nlargest should be smarter/more usable/more consistent

Raymond Hettinger report at bugs.python.org
Fri Jul 31 20:28:14 CEST 2009


Raymond Hettinger <rhettinger at users.sourceforge.net> added the comment:

I prefer the docs the way they are.  They help the reader understand the
relationship between min, max, nsmallest, nlargest, and sorted.

I'm not sure where you got the n * 10 <= len(iterable) switch-over
point.  That is arbitrary.  The correct switchover point depends on the
cost of the comparison function, whether the length of the input is
known, whether the input data is partially ordered, memory constraints,
whether a key function is used, and on other factors.   

FWIW, I also wrote the logic for random.sample().  The switchover logic
was straight-forward because performance depended on factors that were
fully known (length of input, sample size, memory utilization, and
average number of probes for each strategy).

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue6614>
_______________________________________


More information about the Python-bugs-list mailing list