Skip to content

Commit bb0df45

Browse files
committed
Deploying to gh-pages from @ 19039a0 🚀
1 parent ef82f0c commit bb0df45

File tree

529 files changed

+1220
-1148
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

529 files changed

+1220
-1148
lines changed

.buildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Sphinx build info version 1
22
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
3-
config: 17afa962cc865e7d4a9962cb80713add
3+
config: af2eae3e2ebaf3cd5e3156f81a342668
44
tags: 645f666f9bcd5a90fca523b33c5a78b7

_sources/howto/descriptor.rst.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.. _descriptorhowto:
22

3-
======================
4-
Descriptor HowTo Guide
5-
======================
3+
================
4+
Descriptor Guide
5+
================
66

77
:Author: Raymond Hettinger
88
:Contact: <python at rcn dot com>

_sources/howto/sorting.rst.txt

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
.. _sortinghowto:
22

3-
Sorting HOW TO
4-
**************
3+
Sorting Techniques
4+
******************
55

66
:Author: Andrew Dalke and Raymond Hettinger
7-
:Release: 0.1
87

98

109
Python lists have a built-in :meth:`list.sort` method that modifies the list
@@ -56,7 +55,7 @@ For example, here's a case-insensitive string comparison:
5655

5756
.. doctest::
5857

59-
>>> sorted("This is a test string from Andrew".split(), key=str.lower)
58+
>>> sorted("This is a test string from Andrew".split(), key=str.casefold)
6059
['a', 'Andrew', 'from', 'is', 'string', 'test', 'This']
6160

6261
The value of the *key* parameter should be a function (or other callable) that
@@ -97,10 +96,14 @@ The same technique works for objects with named attributes. For example:
9796
>>> sorted(student_objects, key=lambda student: student.age) # sort by age
9897
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
9998

100-
Operator Module Functions
101-
=========================
99+
Objects with named attributes can be made by a regular class as shown
100+
above, or they can be instances of :class:`~dataclasses.dataclass` or
101+
a :term:`named tuple`.
102102

103-
The key-function patterns shown above are very common, so Python provides
103+
Operator Module Functions and Partial Function Evaluation
104+
=========================================================
105+
106+
The :term:`key function` patterns shown above are very common, so Python provides
104107
convenience functions to make accessor functions easier and faster. The
105108
:mod:`operator` module has :func:`~operator.itemgetter`,
106109
:func:`~operator.attrgetter`, and a :func:`~operator.methodcaller` function.
@@ -128,6 +131,24 @@ sort by *grade* then by *age*:
128131
>>> sorted(student_objects, key=attrgetter('grade', 'age'))
129132
[('john', 'A', 15), ('dave', 'B', 10), ('jane', 'B', 12)]
130133

134+
The :mod:`functools` module provides another helpful tool for making
135+
key-functions. The :func:`~functools.partial` function can reduce the
136+
`arity <https://en.wikipedia.org/wiki/Arity>`_ of a multi-argument
137+
function making it suitable for use as a key-function.
138+
139+
.. doctest::
140+
141+
>>> from functools import partial
142+
>>> from unicodedata import normalize
143+
144+
>>> names = 'Zoë Åbjørn Núñez Élana Zeke Abe Nubia Eloise'.split()
145+
146+
>>> sorted(names, key=partial(normalize, 'NFD'))
147+
['Abe', 'Åbjørn', 'Eloise', 'Élana', 'Nubia', 'Núñez', 'Zeke', 'Zoë']
148+
149+
>>> sorted(names, key=partial(normalize, 'NFC'))
150+
['Abe', 'Eloise', 'Nubia', 'Núñez', 'Zeke', 'Zoë', 'Åbjørn', 'Élana']
151+
131152
Ascending and Descending
132153
========================
133154

@@ -200,6 +221,8 @@ This idiom is called Decorate-Sort-Undecorate after its three steps:
200221

201222
For example, to sort the student data by *grade* using the DSU approach:
202223

224+
.. doctest::
225+
203226
>>> decorated = [(student.grade, i, student) for i, student in enumerate(student_objects)]
204227
>>> decorated.sort()
205228
>>> [student for grade, i, student in decorated] # undecorate
@@ -282,7 +305,11 @@ Odds and Ends
282305
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
283306

284307
However, note that ``<`` can fall back to using :meth:`~object.__gt__` if
285-
:meth:`~object.__lt__` is not implemented (see :func:`object.__lt__`).
308+
:meth:`~object.__lt__` is not implemented (see :func:`object.__lt__`
309+
for details on the mechanics). To avoid surprises, :pep:`8`
310+
recommends that all six comparison methods be implemented.
311+
The :func:`~functools.total_ordering` decorator is provided to make that
312+
task easier.
286313

287314
* Key functions need not depend directly on the objects being sorted. A key
288315
function can also access external resources. For instance, if the student grades
@@ -295,3 +322,24 @@ Odds and Ends
295322
>>> newgrades = {'john': 'F', 'jane':'A', 'dave': 'C'}
296323
>>> sorted(students, key=newgrades.__getitem__)
297324
['jane', 'dave', 'john']
325+
326+
Partial Sorts
327+
=============
328+
329+
Some applications require only some of the data to be ordered. The standard
330+
library provides several tools that do less work than a full sort:
331+
332+
* :func:`min` and :func:`max` return the smallest and largest values,
333+
respectively. These functions make a single pass over the input data and
334+
require almost no auxiliary memory.
335+
336+
* :func:`heapq.nsmallest` and :func:`heapq.nlargest` return
337+
the *n* smallest and largest values, respectively. These functions
338+
make a single pass over the data keeping only *n* elements in memory
339+
at a time. For values of *n* that are small relative to the number of
340+
inputs, these functions make far fewer comparisons than a full sort.
341+
342+
* :func:`heapq.heappush` and :func:`heapq.heappop` create and maintain a
343+
partially sorted arrangement of data that keeps the smallest element
344+
at position ``0``. These functions are suitable for implementing
345+
priority queues which are commonly used for task scheduling.

_sources/library/socket.rst.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,8 +1605,9 @@ to sockets.
16051605

16061606
Receive data from the socket. The return value is a bytes object representing the
16071607
data received. The maximum amount of data to be received at once is specified
1608-
by *bufsize*. See the Unix manual page :manpage:`recv(2)` for the meaning of
1609-
the optional argument *flags*; it defaults to zero.
1608+
by *bufsize*. A returned empty bytes object indicates that the client has disconnected.
1609+
See the Unix manual page :manpage:`recv(2)` for the meaning of the optional argument
1610+
*flags*; it defaults to zero.
16101611

16111612
.. note::
16121613

about.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ <h3>瀏覽</h3>
309309
<br />
310310
<br />
311311

312-
最後更新於 Feb 19, 2024 (19:54 UTC)。
312+
最後更新於 Feb 21, 2024 (04:20 UTC)。
313313
<a href="/bugs.html">Found a bug</a>?
314314
<br />
315315

bugs.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ <h3>瀏覽</h3>
345345
<br />
346346
<br />
347347

348-
最後更新於 Feb 19, 2024 (19:54 UTC)。
348+
最後更新於 Feb 21, 2024 (04:20 UTC)。
349349
<a href="/bugs.html">Found a bug</a>?
350350
<br />
351351

c-api/abstract.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ <h3>瀏覽</h3>
319319
<br />
320320
<br />
321321

322-
最後更新於 Feb 19, 2024 (19:54 UTC)。
322+
最後更新於 Feb 21, 2024 (04:20 UTC)。
323323
<a href="/bugs.html">Found a bug</a>?
324324
<br />
325325

c-api/allocation.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ <h3>瀏覽</h3>
333333
<br />
334334
<br />
335335

336-
最後更新於 Feb 19, 2024 (19:54 UTC)。
336+
最後更新於 Feb 21, 2024 (04:20 UTC)。
337337
<a href="/bugs.html">Found a bug</a>?
338338
<br />
339339

c-api/apiabiversion.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ <h3>瀏覽</h3>
365365
<br />
366366
<br />
367367

368-
最後更新於 Feb 19, 2024 (19:54 UTC)。
368+
最後更新於 Feb 21, 2024 (04:20 UTC)。
369369
<a href="/bugs.html">Found a bug</a>?
370370
<br />
371371

c-api/arg.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ <h3>瀏覽</h3>
876876
<br />
877877
<br />
878878

879-
最後更新於 Feb 19, 2024 (19:54 UTC)。
879+
最後更新於 Feb 21, 2024 (04:20 UTC)。
880880
<a href="/bugs.html">Found a bug</a>?
881881
<br />
882882

0 commit comments

Comments
 (0)