Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ba86fa9d
Kaydet (Commit)
ba86fa9d
authored
Şub 21, 2009
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
In Py3.x, a list comprehension is now faster than list(map(itemgetter(0), iterable)).
üst
912fbcad
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
5 deletions
+4
-5
heapq.py
Lib/heapq.py
+4
-5
No files found.
Lib/heapq.py
Dosyayı görüntüle @
ba86fa9d
...
...
@@ -130,7 +130,6 @@ __all__ = ['heappush', 'heappop', 'heapify', 'heapreplace', 'merge',
'nlargest'
,
'nsmallest'
,
'heappushpop'
]
from
itertools
import
islice
,
repeat
,
count
,
tee
,
chain
from
operator
import
itemgetter
import
bisect
def
heappush
(
heap
,
item
):
...
...
@@ -377,13 +376,13 @@ def nsmallest(n, iterable, key=None):
if
key
is
None
:
it
=
zip
(
iterable
,
count
())
# decorate
result
=
_nsmallest
(
n
,
it
)
return
list
(
map
(
itemgetter
(
0
),
result
))
# undecorate
return
[
r
[
0
]
for
r
in
result
]
# undecorate
# General case, slowest method
in1
,
in2
=
tee
(
iterable
)
it
=
zip
(
map
(
key
,
in1
),
count
(),
in2
)
# decorate
result
=
_nsmallest
(
n
,
it
)
return
list
(
map
(
itemgetter
(
2
),
result
))
# undecorate
return
[
r
[
2
]
for
r
in
result
]
# undecorate
_nlargest
=
nlargest
def
nlargest
(
n
,
iterable
,
key
=
None
):
...
...
@@ -415,13 +414,13 @@ def nlargest(n, iterable, key=None):
if
key
is
None
:
it
=
zip
(
iterable
,
count
(
0
,
-
1
))
# decorate
result
=
_nlargest
(
n
,
it
)
return
list
(
map
(
itemgetter
(
0
),
result
))
# undecorate
return
[
r
[
0
]
for
r
in
result
]
# undecorate
# General case, slowest method
in1
,
in2
=
tee
(
iterable
)
it
=
zip
(
map
(
key
,
in1
),
count
(
0
,
-
1
),
in2
)
# decorate
result
=
_nlargest
(
n
,
it
)
return
list
(
map
(
itemgetter
(
2
),
result
))
# undecorate
return
[
r
[
2
]
for
r
in
result
]
# undecorate
if
__name__
==
"__main__"
:
# Simple sanity test
...
...
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