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
378a1d77
Kaydet (Commit)
378a1d77
authored
Agu 09, 2016
tarafından
Zachary Ware
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #27204: Fix doctests in Doc/howto
Patch by Jelle Zijlstra.
üst
2f47fb00
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
24 deletions
+29
-24
functional.rst
Doc/howto/functional.rst
+1
-1
ipaddress.rst
Doc/howto/ipaddress.rst
+4
-5
sorting.rst
Doc/howto/sorting.rst
+24
-18
No files found.
Doc/howto/functional.rst
Dosyayı görüntüle @
378a1d77
...
...
@@ -1040,7 +1040,7 @@ If you use :func:`operator.add` with :func:`functools.reduce`, you'll add up all
elements of the iterable. This case is so common that there's a special
built-in called :func:`sum` to compute it:
>>> import functools
>>> import functools
, operator
>>> functools.reduce(operator.add, [1,2,3,4], 0)
10
>>> sum([1,2,3,4])
...
...
Doc/howto/ipaddress.rst
Dosyayı görüntüle @
378a1d77
.. testsetup::
import ipaddress
.. _ipaddress-howto:
***************************************
...
...
@@ -49,11 +53,6 @@ to use the :func:`ipaddress.ip_address` factory function, which automatically
determines whether to create an IPv4 or IPv6 address based on the passed in
value:
.. testsetup::
>>> import ipaddress
::
>>> ipaddress.ip_address('192.0.2.1')
IPv4Address('192.0.2.1')
>>> ipaddress.ip_address('2001:DB8::1')
...
...
Doc/howto/sorting.rst
Dosyayı görüntüle @
378a1d77
...
...
@@ -58,28 +58,28 @@ A common pattern is to sort complex objects using some of the object's indices
as keys. For example:
>>> student_tuples = [
('john', 'A', 15),
('jane', 'B', 12),
('dave', 'B', 10),
]
...
('john', 'A', 15),
...
('jane', 'B', 12),
...
('dave', 'B', 10),
...
]
>>> sorted(student_tuples, key=lambda student: student[2]) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
The same technique works for objects with named attributes. For example:
>>> class Student:
def __init__(self, name, grade, age):
self.name = name
self.grade = grade
self.age = age
def __repr__(self):
return repr((self.name, self.grade, self.age))
...
def __init__(self, name, grade, age):
...
self.name = name
...
self.grade = grade
...
self.age = age
...
def __repr__(self):
...
return repr((self.name, self.grade, self.age))
>>> student_objects = [
Student('john', 'A', 15),
Student('jane', 'B', 12),
Student('dave', 'B', 10),
]
...
Student('john', 'A', 15),
...
Student('jane', 'B', 12),
...
Student('dave', 'B', 10),
...
]
>>> sorted(student_objects, key=lambda student: student.age) # sort by age
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
...
...
@@ -208,15 +208,15 @@ return a negative value for less-than, return zero if they are equal, or return
a positive value for greater-than. For example, we can do:
>>> def numeric_compare(x, y):
return x - y
>>> sorted([5, 2, 4, 1, 3], cmp=numeric_compare)
...
return x - y
>>> sorted([5, 2, 4, 1, 3], cmp=numeric_compare)
# doctest: +SKIP
[1, 2, 3, 4, 5]
Or you can reverse the order of comparison with:
>>> def reverse_numeric(x, y):
return y - x
>>> sorted([5, 2, 4, 1, 3], cmp=reverse_numeric)
...
return y - x
>>> sorted([5, 2, 4, 1, 3], cmp=reverse_numeric)
# doctest: +SKIP
[5, 4, 3, 2, 1]
When porting code from Python 2.x to 3.x, the situation can arise when you have
...
...
@@ -244,6 +244,12 @@ function. The following wrapper makes that easy to do::
To convert to a key function, just wrap the old comparison function:
.. testsetup::
from functools import cmp_to_key
.. doctest::
>>> sorted([5, 2, 4, 1, 3], key=cmp_to_key(reverse_numeric))
[5, 4, 3, 2, 1]
...
...
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