Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
bd171bcf
Commit
bd171bcf
authored
Feb 21, 2009
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port r69838: Speedup and simplify negative counter using count's new step argument.
parent
934896dc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
3 deletions
+3
-3
Lib/heapq.py
Lib/heapq.py
+3
-3
No files found.
Lib/heapq.py
View file @
bd171bcf
...
...
@@ -130,7 +130,7 @@ __all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'merge',
'nlargest'
,
'nsmallest'
,
'heappushpop'
]
from
itertools
import
islice
,
repeat
,
count
,
tee
,
chain
from
operator
import
itemgetter
,
neg
from
operator
import
itemgetter
import
bisect
def
heappush
(
heap
,
item
):
...
...
@@ -413,13 +413,13 @@ def nlargest(n, iterable, key=None):
# When key is none, use simpler decoration
if
key
is
None
:
it
=
zip
(
iterable
,
map
(
neg
,
count
()))
# decorate
it
=
zip
(
iterable
,
count
(
0
,
-
1
))
# decorate
result
=
_nlargest
(
n
,
it
)
return
list
(
map
(
itemgetter
(
0
),
result
))
# undecorate
# General case, slowest method
in1
,
in2
=
tee
(
iterable
)
it
=
zip
(
map
(
key
,
in1
),
map
(
neg
,
count
()),
in2
)
# decorate
it
=
zip
(
map
(
key
,
in1
),
count
(
0
,
-
1
),
in2
)
# decorate
result
=
_nlargest
(
n
,
it
)
return
list
(
map
(
itemgetter
(
2
),
result
))
# undecorate
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment