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
4c97a62a
Kaydet (Commit)
4c97a62a
authored
May 30, 2015
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #23509: Speed up Counter operators
(Based on patch by Serhiy Storchaka.)
üst
3d1151d2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
2 deletions
+10
-2
__init__.py
Lib/collections/__init__.py
+10
-2
No files found.
Lib/collections/__init__.py
Dosyayı görüntüle @
4c97a62a
...
@@ -753,14 +753,22 @@ class Counter(dict):
...
@@ -753,14 +753,22 @@ class Counter(dict):
def
__pos__
(
self
):
def
__pos__
(
self
):
'Adds an empty counter, effectively stripping negative and zero counts'
'Adds an empty counter, effectively stripping negative and zero counts'
return
self
+
Counter
()
result
=
Counter
()
for
elem
,
count
in
self
.
items
():
if
count
>
0
:
result
[
elem
]
=
count
return
result
def
__neg__
(
self
):
def
__neg__
(
self
):
'''Subtracts from an empty counter. Strips positive and zero counts,
'''Subtracts from an empty counter. Strips positive and zero counts,
and flips the sign on negative counts.
and flips the sign on negative counts.
'''
'''
return
Counter
()
-
self
result
=
Counter
()
for
elem
,
count
in
self
.
items
():
if
count
<
0
:
result
[
elem
]
=
0
-
count
return
result
def
_keep_positive
(
self
):
def
_keep_positive
(
self
):
'''Internal method to strip elements with a negative or zero count'''
'''Internal method to strip elements with a negative or zero count'''
...
...
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