diff options
author | Raymond Hettinger <python@rcn.com> | 2008-03-13 19:33:34 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2008-03-13 19:33:34 (GMT) |
commit | 83aa6a3b1a6a406b3cde2fa7daa5d5b1db0cc6a7 (patch) | |
tree | 3f9d71d12360e412dce2a6ee48636e37599951e4 /Lib | |
parent | 53bdf093437349907807da9143f9c2bdcea9ab3a (diff) | |
download | cpython-83aa6a3b1a6a406b3cde2fa7daa5d5b1db0cc6a7.zip cpython-83aa6a3b1a6a406b3cde2fa7daa5d5b1db0cc6a7.tar.gz cpython-83aa6a3b1a6a406b3cde2fa7daa5d5b1db0cc6a7.tar.bz2 |
Simplify the nlargest() code using heappushpop().
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/heapq.py | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/Lib/heapq.py b/Lib/heapq.py index 23f5fcb..4af9af1 100644 --- a/Lib/heapq.py +++ b/Lib/heapq.py @@ -193,13 +193,9 @@ def nlargest(n, iterable): if not result: return result heapify(result) - _heapreplace = heapreplace - sol = result[0] # sol --> smallest of the nlargest + _heappushpop = heappushpop for elem in it: - if elem <= sol: - continue - _heapreplace(result, elem) - sol = result[0] + heappushpop(result, elem) result.sort(reverse=True) return result |