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
16ffbc3d
Kaydet (Commit)
16ffbc3d
authored
Tem 01, 2005
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Provide a comparison to the builtin set types.
üst
c418cc81
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
2 deletions
+32
-2
libsets.tex
Doc/lib/libsets.tex
+32
-2
No files found.
Doc/lib/libsets.tex
Dosyayı görüntüle @
16ffbc3d
...
...
@@ -133,7 +133,7 @@ The following table lists operations available in \class{Set}
but not found in
\class
{
ImmutableSet
}
:
\begin{tableiii}
{
c|c|l
}{
code
}{
Operation
}{
Equivalent
}{
Result
}
\lineiii
{
\var
{
s
}
.u
nion
_
u
pdate(
\var
{
t
}
)
}
\lineiii
{
\var
{
s
}
.update(
\var
{
t
}
)
}
{
\var
{
s
}
\textbar
=
\var
{
t
}}
{
return set
\var
{
s
}
with elements added from
\var
{
t
}}
\lineiii
{
\var
{
s
}
.intersection
_
update(
\var
{
t
}
)
}
...
...
@@ -161,12 +161,17 @@ but not found in \class{ImmutableSet}:
{
remove all elements from set
\var
{
s
}}
\end{tableiii}
Note, the non-operator versions of
\method
{
u
nion
_
u
pdate()
}
,
Note, the non-operator versions of
\method
{
update()
}
,
\method
{
intersection
_
update()
}
,
\method
{
difference
_
update()
}
, and
\method
{
symmetric
_
difference
_
update()
}
will accept any iterable as
an argument.
\versionchanged
[Formerly all arguments were required to be sets]
{
2.3.1
}
Also note, the module also includes a
\method
{
union
_
update()
}
method
which is an alias for
\method
{
update()
}
. The method is included for
backwards compatability. Programmers should prefer the
\method
{
update()
}
method because it the one supported by the builtin
\class
{
set()
}
and
\class
{
frozenset()
}
types.
\subsection
{
Example
\label
{
set-example
}}
...
...
@@ -231,3 +236,28 @@ user; however, a conflict can arise in a multi-threaded environment
where one thread is updating a set while another has temporarily wrapped it
in
\class
{_
TemporarilyImmutableSet
}
. In other words, sets of mutable sets
are not thread-safe.
\subsection
{
Comparison to the built-in
\class
{
set
}
types
\label
{
comparison-to-builtin-set
}}
The built-in
\class
{
set
}
and
\class
{
frozenset
}
types were designed based
on lessons learned from the
\module
{
sets
}
module. The key differences are:
\begin{itemize}
\item
\class
{
Set
}
and
\class
{
ImmutableSet
}
were renamed to
\class
{
set
}
and
\class
{
frozenset
}
.
\item
There is no equivalent to
\class
{
BaseSet
}
. Instead, use
\code
{
isinstance(x, (set, frozenset))
}
.
\item
The hash algorithm for the built-ins performs significantly better
(fewer collisions) for most datasets.
\item
The built-in versions have more space efficient pickles.
\item
The built-in versions do not have a
\method
{
union
_
update()
}
method.
Instead, use the
\method
{
update()
}
method which is equivalent.
\item
The built-in versions do not have a
\method
{_
repr(sort=True)
}
method.
Instead, use the built-in
\function
{
repr()
}
and
\function
{
sorted()
}
functions:
\code
{
repr(sorted(s))
}
.
\item
The built-in version does not have a protocol for automatic conversion
to immutable. Many found this feature to be confusing and no one
in the community reported having found real uses for it.
\end{itemize}
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