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
4abd5f0f
Kaydet (Commit)
4abd5f0f
authored
Ock 02, 2003
tarafından
Skip Montanaro
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Allow list sort's comparison function to explicitly be None. See SF patch
661092.
üst
fe8496ca
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
6 deletions
+34
-6
libstdtypes.tex
Doc/lib/libstdtypes.tex
+6
-5
test_sort.py
Lib/test/test_sort.py
+20
-0
NEWS
Misc/NEWS
+4
-0
listobject.c
Objects/listobject.c
+4
-1
No files found.
Doc/lib/libstdtypes.tex
Dosyayı görüntüle @
4abd5f0f
...
@@ -925,7 +925,7 @@ The following operations are defined on mutable sequence types (where
...
@@ -925,7 +925,7 @@ The following operations are defined on mutable sequence types (where
{
same as
\code
{
del
\var
{
s
}
[
\var
{
s
}
.index(
\var
{
x
}
)]
}}{
(3)
}
{
same as
\code
{
del
\var
{
s
}
[
\var
{
s
}
.index(
\var
{
x
}
)]
}}{
(3)
}
\lineiii
{
\var
{
s
}
.reverse()
}
\lineiii
{
\var
{
s
}
.reverse()
}
{
reverses the items of
\var
{
s
}
in place
}{
(6)
}
{
reverses the items of
\var
{
s
}
in place
}{
(6)
}
\lineiii
{
\var
{
s
}
.sort(
\optional
{
\var
{
cmpfunc
}}
)
}
\lineiii
{
\var
{
s
}
.sort(
\optional
{
\var
{
cmpfunc
=None
}}
)
}
{
sort the items of
\var
{
s
}
in place
}{
(6), (7), (8), (9)
}
{
sort the items of
\var
{
s
}
in place
}{
(6), (7), (8), (9)
}
\end{tableiii}
\end{tableiii}
\indexiv
{
operations on
}{
mutable
}{
sequence
}{
types
}
\indexiv
{
operations on
}{
mutable
}{
sequence
}{
types
}
...
@@ -970,10 +970,11 @@ Notes:
...
@@ -970,10 +970,11 @@ Notes:
the first argument is considered smaller than, equal to, or larger
the first argument is considered smaller than, equal to, or larger
than the second argument. Note that this slows the sorting process
than the second argument. Note that this slows the sorting process
down considerably; e.g. to sort a list in reverse order it is much
down considerably; e.g. to sort a list in reverse order it is much
faster to call method
\method
{
sort()
}
followed by
faster to call method
\method
{
sort()
}
followed by
\method
{
reverse()
}
\method
{
reverse()
}
than to use method
than to use method
\method
{
sort()
}
with a comparison function that
\method
{
sort()
}
with a comparison function that reverses the
reverses the ordering of the elements. Passing
\constant
{
None
}
as the
ordering of the elements.
comparison function is semantically equivalent to calling
\method
{
sort()
}
with no comparison function.
\item
[(8)]
Whether the
\method
{
sort()
}
method is stable is not defined by
\item
[(8)]
Whether the
\method
{
sort()
}
method is stable is not defined by
the language (a sort is stable if it guarantees not to change the
the language (a sort is stable if it guarantees not to change the
...
...
Lib/test/test_sort.py
Dosyayı görüntüle @
4abd5f0f
...
@@ -145,6 +145,26 @@ def bug453523():
...
@@ -145,6 +145,26 @@ def bug453523():
bug453523
()
bug453523
()
def
cmpNone
():
global
nerrors
if
verbose
:
print
"Testing None as a comparison function."
L
=
range
(
50
)
random
.
shuffle
(
L
)
try
:
L
.
sort
(
None
)
except
TypeError
:
print
" Passing None as cmpfunc failed."
nerrors
+=
1
else
:
if
L
!=
range
(
50
):
print
" Passing None as cmpfunc failed."
nerrors
+=
1
cmpNone
()
if
nerrors
:
if
nerrors
:
print
"Test failed"
,
nerrors
print
"Test failed"
,
nerrors
elif
verbose
:
elif
verbose
:
...
...
Misc/NEWS
Dosyayı görüntüle @
4abd5f0f
...
@@ -12,6 +12,10 @@ What's New in Python 2.3 alpha 2?
...
@@ -12,6 +12,10 @@ What's New in Python 2.3 alpha 2?
Core and builtins
Core and builtins
-----------------
-----------------
- List objects'
sort
()
method
now
accepts
None
as
the
comparison
function
.
Passing
None
is
semantically
identical
to
calling
sort
()
with
no
arguments
.
Extension
modules
Extension
modules
-----------------
-----------------
...
...
Objects/listobject.c
Dosyayı görüntüle @
4abd5f0f
...
@@ -1657,6 +1657,9 @@ listsort(PyListObject *self, PyObject *args)
...
@@ -1657,6 +1657,9 @@ listsort(PyListObject *self, PyObject *args)
if
(
!
PyArg_UnpackTuple
(
args
,
"sort"
,
0
,
1
,
&
compare
))
if
(
!
PyArg_UnpackTuple
(
args
,
"sort"
,
0
,
1
,
&
compare
))
return
NULL
;
return
NULL
;
}
}
if
(
compare
==
Py_None
)
compare
=
NULL
;
merge_init
(
&
ms
,
compare
);
merge_init
(
&
ms
,
compare
);
/* The list is temporarily made empty, so that mutations performed
/* The list is temporarily made empty, so that mutations performed
...
@@ -2069,7 +2072,7 @@ PyDoc_STRVAR(count_doc,
...
@@ -2069,7 +2072,7 @@ PyDoc_STRVAR(count_doc,
PyDoc_STRVAR
(
reverse_doc
,
PyDoc_STRVAR
(
reverse_doc
,
"L.reverse() -- reverse *IN PLACE*"
);
"L.reverse() -- reverse *IN PLACE*"
);
PyDoc_STRVAR
(
sort_doc
,
PyDoc_STRVAR
(
sort_doc
,
"L.sort(
[cmpfunc]
) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1"
);
"L.sort(
cmpfunc=None
) -- stable sort *IN PLACE*; cmpfunc(x, y) -> -1, 0, 1"
);
static
PyMethodDef
list_methods
[]
=
{
static
PyMethodDef
list_methods
[]
=
{
{
"append"
,
(
PyCFunction
)
listappend
,
METH_O
,
append_doc
},
{
"append"
,
(
PyCFunction
)
listappend
,
METH_O
,
append_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