[Python-checkins] r61370 - python/trunk/Lib/heapq.py
raymond.hettinger
python-checkins at python.org
Thu Mar 13 20:33:35 CET 2008
Author: raymond.hettinger
Date: Thu Mar 13 20:33:34 2008
New Revision: 61370
Modified:
python/trunk/Lib/heapq.py
Log:
Simplify the nlargest() code using heappushpop().
Modified: python/trunk/Lib/heapq.py
==============================================================================
--- python/trunk/Lib/heapq.py (original)
+++ python/trunk/Lib/heapq.py Thu Mar 13 20:33:34 2008
@@ -193,13 +193,9 @@
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
More information about the Python-checkins
mailing list