<div dir="ltr">The current heapq documentation states that:<div><br></div><div>- heapq.nlargest(n, iterable[, key]) is "Equivalent to: sorted(iterable, key=key, reverse=True)[:n]"</div><div><br></div><div>- heapq.nsmallest(n, iterable[, key]) is "Equivalent to: sorted(iterable, key=key)[:n]"</div>
<div><br></div><div>However, this does not hold true when n = None. Specifically, heapq throws an exception while slicing appears to produce a shallow copy of the sorted list.</div><div><br></div><div>Thanks!</div><div>--Tristan</div>
</div>