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
4267be64
Kaydet (Commit)
4267be64
authored
Haz 11, 2008
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Multi-arg form for set.difference() and set.difference_update().
üst
9d53457e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
66 additions
and
21 deletions
+66
-21
stdtypes.rst
Doc/library/stdtypes.rst
+12
-6
test_set.py
Lib/test/test_set.py
+14
-0
NEWS
Misc/NEWS
+1
-1
setobject.c
Objects/setobject.c
+39
-14
No files found.
Doc/library/stdtypes.rst
Dosyayı görüntüle @
4267be64
...
...
@@ -1583,10 +1583,13 @@ The constructors for both classes work the same:
.. versionchanged:: 2.6
Accepts multiple input iterables.
.. method:: difference(other)
set - other
.. method:: difference(other
, ...
)
set - other
- ...
Return a new set with elements in the set that are not in *other*.
Return a new set with elements in the set that are not in the others.
.. versionchanged:: 2.6
Accepts multiple input iterables.
.. method:: symmetric_difference(other)
set ^ other
...
...
@@ -1650,10 +1653,13 @@ The constructors for both classes work the same:
.. versionchanged:: 2.6
Accepts multiple input iterables.
.. method:: difference_update(other)
set -= other
.. method:: difference_update(other
, ...
)
set -= other
| ...
Update the set, removing elements found in *other*.
Update the set, removing elements found in others.
.. versionchanged:: 2.6
Accepts multiple input iterables.
.. method:: symmetric_difference_update(other)
set ^= other
...
...
Lib/test/test_set.py
Dosyayı görüntüle @
4267be64
...
...
@@ -149,6 +149,8 @@ class TestJointOps(unittest.TestCase):
self
.
assertEqual
(
self
.
thetype
(
'abcba'
)
.
difference
(
C
(
'efgfe'
)),
set
(
'abc'
))
self
.
assertEqual
(
self
.
thetype
(
'abcba'
)
.
difference
(
C
(
'ccb'
)),
set
(
'a'
))
self
.
assertEqual
(
self
.
thetype
(
'abcba'
)
.
difference
(
C
(
'ef'
)),
set
(
'abc'
))
self
.
assertEqual
(
self
.
thetype
(
'abcba'
)
.
difference
(),
set
(
'abc'
))
self
.
assertEqual
(
self
.
thetype
(
'abcba'
)
.
difference
(
C
(
'a'
),
C
(
'b'
)),
set
(
'c'
))
def
test_sub
(
self
):
i
=
self
.
s
.
difference
(
self
.
otherword
)
...
...
@@ -467,6 +469,18 @@ class TestSet(TestJointOps):
self
.
assertEqual
(
s
.
difference_update
(
C
(
p
)),
None
)
self
.
assertEqual
(
s
,
set
(
q
))
s
=
self
.
thetype
(
'abcdefghih'
)
s
.
difference_update
()
self
.
assertEqual
(
s
,
self
.
thetype
(
'abcdefghih'
))
s
=
self
.
thetype
(
'abcdefghih'
)
s
.
difference_update
(
C
(
'aba'
))
self
.
assertEqual
(
s
,
self
.
thetype
(
'cdefghih'
))
s
=
self
.
thetype
(
'abcdefghih'
)
s
.
difference_update
(
C
(
'cdc'
),
C
(
'aba'
))
self
.
assertEqual
(
s
,
self
.
thetype
(
'efghih'
))
def
test_isub
(
self
):
self
.
s
-=
set
(
self
.
otherword
)
for
c
in
(
self
.
word
+
self
.
otherword
):
...
...
Misc/NEWS
Dosyayı görüntüle @
4267be64
...
...
@@ -13,7 +13,7 @@ Core and Builtins
-----------------
- Several set methods now accept multiple arguments: update(), union(),
intersection()
and intersection
_update().
intersection()
, intersection_update(), difference(), and difference
_update().
- Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
...
...
Objects/setobject.c
Dosyayı görüntüle @
4267be64
...
...
@@ -1495,11 +1495,16 @@ set_difference_update_internal(PySetObject *so, PyObject *other)
}
static
PyObject
*
set_difference_update
(
PySetObject
*
so
,
PyObject
*
other
)
set_difference_update
(
PySetObject
*
so
,
PyObject
*
args
)
{
if
(
set_difference_update_internal
(
so
,
other
)
!=
-
1
)
Py_RETURN_NONE
;
return
NULL
;
Py_ssize_t
i
;
for
(
i
=
0
;
i
<
PyTuple_GET_SIZE
(
args
)
;
i
++
)
{
PyObject
*
other
=
PyTuple_GET_ITEM
(
args
,
i
);
if
(
set_difference_update_internal
(
so
,
other
)
==
-
1
)
return
NULL
;
}
Py_RETURN_NONE
;
}
PyDoc_STRVAR
(
difference_update_doc
,
...
...
@@ -1557,10 +1562,34 @@ set_difference(PySetObject *so, PyObject *other)
return
result
;
}
static
PyObject
*
set_difference_multi
(
PySetObject
*
so
,
PyObject
*
args
)
{
Py_ssize_t
i
;
PyObject
*
result
,
*
other
;
if
(
PyTuple_GET_SIZE
(
args
)
==
0
)
return
set_copy
(
so
);
other
=
PyTuple_GET_ITEM
(
args
,
0
);
result
=
set_difference
(
so
,
other
);
if
(
result
==
NULL
)
return
NULL
;
for
(
i
=
1
;
i
<
PyTuple_GET_SIZE
(
args
)
;
i
++
)
{
other
=
PyTuple_GET_ITEM
(
args
,
i
);
if
(
set_difference_update_internal
((
PySetObject
*
)
result
,
other
)
==
-
1
)
{
Py_DECREF
(
result
);
return
NULL
;
}
}
return
result
;
}
PyDoc_STRVAR
(
difference_doc
,
"Return the difference of two sets as a new set.
\n
\
"Return the difference of two
or more
sets as a new set.
\n
\
\n
\
(i.e. all elements that are in this set but not the other.)"
);
(i.e. all elements that are in this set but not the other
s
.)"
);
static
PyObject
*
set_sub
(
PySetObject
*
so
,
PyObject
*
other
)
{
...
...
@@ -1574,16 +1603,12 @@ set_sub(PySetObject *so, PyObject *other)
static
PyObject
*
set_isub
(
PySetObject
*
so
,
PyObject
*
other
)
{
PyObject
*
result
;
if
(
!
PyAnySet_Check
(
other
))
{
Py_INCREF
(
Py_NotImplemented
);
return
Py_NotImplemented
;
}
result
=
set_difference_update
(
so
,
other
);
if
(
result
==
NULL
)
if
(
set_difference_update_internal
(
so
,
other
)
==
-
1
)
return
NULL
;
Py_DECREF
(
result
);
Py_INCREF
(
so
);
return
(
PyObject
*
)
so
;
}
...
...
@@ -1978,9 +2003,9 @@ static PyMethodDef set_methods[] = {
copy_doc
},
{
"discard"
,
(
PyCFunction
)
set_discard
,
METH_O
,
discard_doc
},
{
"difference"
,
(
PyCFunction
)
set_difference
,
METH_O
,
{
"difference"
,
(
PyCFunction
)
set_difference
_multi
,
METH_VARARGS
,
difference_doc
},
{
"difference_update"
,
(
PyCFunction
)
set_difference_update
,
METH_
O
,
{
"difference_update"
,
(
PyCFunction
)
set_difference_update
,
METH_
VARARGS
,
difference_update_doc
},
{
"intersection"
,(
PyCFunction
)
set_intersection_multi
,
METH_VARARGS
,
intersection_doc
},
...
...
@@ -2107,7 +2132,7 @@ static PyMethodDef frozenset_methods[] = {
contains_doc
},
{
"copy"
,
(
PyCFunction
)
frozenset_copy
,
METH_NOARGS
,
copy_doc
},
{
"difference"
,
(
PyCFunction
)
set_difference
,
METH_O
,
{
"difference"
,
(
PyCFunction
)
set_difference
_multi
,
METH_VARARGS
,
difference_doc
},
{
"intersection"
,(
PyCFunction
)
set_intersection_multi
,
METH_VARARGS
,
intersection_doc
},
...
...
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