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
efeb8bda
Kaydet (Commit)
efeb8bda
authored
Nis 18, 2011
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Rework multiset methods to use less memory and to make fewer calls to __hash__.
üst
c116da04
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
12 deletions
+19
-12
collections.py
Lib/collections.py
+19
-12
No files found.
Lib/collections.py
Dosyayı görüntüle @
efeb8bda
...
...
@@ -552,10 +552,13 @@ class Counter(dict):
if
not
isinstance
(
other
,
Counter
):
return
NotImplemented
result
=
Counter
()
for
elem
in
set
(
self
)
|
set
(
other
):
newcount
=
self
[
elem
]
+
other
[
elem
]
for
elem
,
count
in
self
.
items
(
):
newcount
=
count
+
other
[
elem
]
if
newcount
>
0
:
result
[
elem
]
=
newcount
for
elem
,
count
in
other
.
items
():
if
elem
not
in
self
and
count
>
0
:
result
[
elem
]
=
count
return
result
def
__sub__
(
self
,
other
):
...
...
@@ -568,10 +571,13 @@ class Counter(dict):
if
not
isinstance
(
other
,
Counter
):
return
NotImplemented
result
=
Counter
()
for
elem
in
set
(
self
)
|
set
(
other
):
newcount
=
self
[
elem
]
-
other
[
elem
]
for
elem
,
count
in
self
.
items
(
):
newcount
=
count
-
other
[
elem
]
if
newcount
>
0
:
result
[
elem
]
=
newcount
for
elem
,
count
in
other
.
items
():
if
elem
not
in
self
and
count
<
0
:
result
[
elem
]
=
0
-
count
return
result
def
__or__
(
self
,
other
):
...
...
@@ -584,11 +590,14 @@ class Counter(dict):
if
not
isinstance
(
other
,
Counter
):
return
NotImplemented
result
=
Counter
()
for
elem
in
set
(
self
)
|
set
(
other
):
p
,
q
=
self
[
elem
],
other
[
elem
]
newcount
=
q
if
p
<
q
else
p
for
elem
,
count
in
self
.
items
(
):
other_count
=
other
[
elem
]
newcount
=
other_count
if
count
<
other_count
else
count
if
newcount
>
0
:
result
[
elem
]
=
newcount
for
elem
,
count
in
other
.
items
():
if
elem
not
in
self
and
count
>
0
:
result
[
elem
]
=
count
return
result
def
__and__
(
self
,
other
):
...
...
@@ -601,11 +610,9 @@ class Counter(dict):
if
not
isinstance
(
other
,
Counter
):
return
NotImplemented
result
=
Counter
()
if
len
(
self
)
<
len
(
other
):
self
,
other
=
other
,
self
for
elem
in
_ifilter
(
self
.
__contains__
,
other
):
p
,
q
=
self
[
elem
],
other
[
elem
]
newcount
=
p
if
p
<
q
else
q
for
elem
,
count
in
self
.
items
():
other_count
=
other
[
elem
]
newcount
=
count
if
count
<
other_count
else
other_count
if
newcount
>
0
:
result
[
elem
]
=
newcount
return
result
...
...
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