@@ -11,7 +11,7 @@ msgid ""
1111msgstr ""
1212"Project-Id-Version : Python 3.9\n "
1313"Report-Msgid-Bugs-To : \n "
14- "POT-Creation-Date : 2025-01-03 16:35 +0000\n "
14+ "POT-Creation-Date : 2025-09-22 21:56 +0000\n "
1515"PO-Revision-Date : 2025-09-22 17:54+0000\n "
1616"Last-Translator : python-doc bot, 2025\n "
1717"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -23,40 +23,40 @@ msgstr ""
2323
2424#: ../../howto/sorting.rst:4
2525msgid "Sorting HOW TO"
26- msgstr ""
26+ msgstr "排序指南 "
2727
2828#: ../../howto/sorting.rst:0
2929msgid "Author"
3030msgstr "作者"
3131
3232#: ../../howto/sorting.rst:6
3333msgid "Andrew Dalke and Raymond Hettinger"
34- msgstr ""
34+ msgstr "Andrew Dalke 与 Raymond Hettinger "
3535
3636#: ../../howto/sorting.rst:0
3737msgid "Release"
3838msgstr "发布版本"
3939
4040#: ../../howto/sorting.rst:7
4141msgid "0.1"
42- msgstr ""
42+ msgstr "0.1 "
4343
4444#: ../../howto/sorting.rst:10
4545msgid ""
4646"Python lists have a built-in :meth:`list.sort` method that modifies the list"
4747" in-place. There is also a :func:`sorted` built-in function that builds a "
4848"new sorted list from an iterable."
49- msgstr ""
49+ msgstr "内置列表方法 :meth:`list.sort` 原地修改列表,而内置函数 :func:`sorted` 由可迭代对象新建有序列表。 "
5050
5151#: ../../howto/sorting.rst:14
5252msgid ""
5353"In this document, we explore the various techniques for sorting data using "
5454"Python."
55- msgstr ""
55+ msgstr "在本文档中,我们将探索使用 Python 对数据进行排序的各种技术。 "
5656
5757#: ../../howto/sorting.rst:18
5858msgid "Sorting Basics"
59- msgstr ""
59+ msgstr "排序的基础知识 "
6060
6161#: ../../howto/sorting.rst:20
6262msgid ""
@@ -71,50 +71,54 @@ msgid ""
7171"than :func:`sorted` - but if you don't need the original list, it's slightly"
7272" more efficient."
7373msgstr ""
74+ "亦可用 :meth:`list.sort` 方法。它原地修改原列表(并返回 ``None`` 以避免混淆)。往往不如 :func:`sorted` "
75+ "方便——但若不需原列表,用它会略高效些。"
7476
7577#: ../../howto/sorting.rst:36
7678msgid ""
7779"Another difference is that the :meth:`list.sort` method is only defined for "
7880"lists. In contrast, the :func:`sorted` function accepts any iterable."
79- msgstr ""
81+ msgstr "另一个区别是 :meth:`list.sort` 方法只为列表定义,而 :func:`sorted` 函数接受任何可迭代对象。 "
8082
8183#: ../../howto/sorting.rst:43
8284msgid "Key Functions"
83- msgstr ""
85+ msgstr "键函数 "
8486
8587#: ../../howto/sorting.rst:45
8688msgid ""
8789"Both :meth:`list.sort` and :func:`sorted` have a *key* parameter to specify "
8890"a function (or other callable) to be called on each list element prior to "
8991"making comparisons."
9092msgstr ""
93+ ":meth:`list.sort` 和 :func:`sorted` 皆有 *key* "
94+ "形参用以指定在比较前要对每个列表元素调用的函数(或其它可调用对象)。"
9195
9296#: ../../howto/sorting.rst:49
9397msgid "For example, here's a case-insensitive string comparison:"
94- msgstr ""
98+ msgstr "例如,这是个不区分大小写的字符串比较: "
9599
96100#: ../../howto/sorting.rst:54
97101msgid ""
98102"The value of the *key* parameter should be a function (or other callable) "
99103"that takes a single argument and returns a key to use for sorting purposes. "
100104"This technique is fast because the key function is called exactly once for "
101105"each input record."
102- msgstr ""
106+ msgstr "*key* 形参的值需为一元函数(或其它可调用对象),其返回值用于排序。这很快,因为键函数只需在输入的每个记录上调用恰好一次。 "
103107
104108#: ../../howto/sorting.rst:59
105109msgid ""
106110"A common pattern is to sort complex objects using some of the object's "
107111"indices as keys. For example:"
108- msgstr ""
112+ msgstr "常见的模式是用对象的某一些索引作为键对复杂对象排序。例如: "
109113
110114#: ../../howto/sorting.rst:70
111115msgid ""
112116"The same technique works for objects with named attributes. For example:"
113- msgstr ""
117+ msgstr "同样的方法对于有具名属性的对象也适用。例如: "
114118
115119#: ../../howto/sorting.rst:89
116120msgid "Operator Module Functions"
117- msgstr ""
121+ msgstr "Operator 模块函数 "
118122
119123#: ../../howto/sorting.rst:91
120124msgid ""
@@ -123,31 +127,36 @@ msgid ""
123127":mod:`operator` module has :func:`~operator.itemgetter`, "
124128":func:`~operator.attrgetter`, and a :func:`~operator.methodcaller` function."
125129msgstr ""
130+ "上面显示的键函数模式非常常见,因此 Python 提供了便利功能,使访问器功能更容易,更快捷。 :mod:`operator` 模块有 "
131+ ":func:`~operator.itemgetter` 、 :func:`~operator.attrgetter` 和 "
132+ ":func:`~operator.methodcaller` 函数。"
126133
127134#: ../../howto/sorting.rst:96
128135msgid "Using those functions, the above examples become simpler and faster:"
129- msgstr ""
136+ msgstr "用了那些函数之后,前面的示例变得更简单,运行起来也更快: "
130137
131138#: ../../howto/sorting.rst:106
132139msgid ""
133140"The operator module functions allow multiple levels of sorting. For example,"
134141" to sort by *grade* then by *age*:"
135- msgstr ""
142+ msgstr "运算符模块的函数可以用来作多级排序。例如,按 *grade* 排序,然后按 *age* 排序: "
136143
137144#: ../../howto/sorting.rst:116
138145msgid "Ascending and Descending"
139- msgstr ""
146+ msgstr "升序与降序 "
140147
141148#: ../../howto/sorting.rst:118
142149msgid ""
143150"Both :meth:`list.sort` and :func:`sorted` accept a *reverse* parameter with "
144151"a boolean value. This is used to flag descending sorts. For example, to get "
145152"the student data in reverse *age* order:"
146153msgstr ""
154+ ":meth:`list.sort` 和 :func:`sorted` 接受布尔形参 *reverse* 用于标记降序排序。例如,将学生数据按 *age*"
155+ " 倒序排序:"
147156
148157#: ../../howto/sorting.rst:129
149158msgid "Sort Stability and Complex Sorts"
150- msgstr ""
159+ msgstr "排序稳定性与复杂排序 "
151160
152161#: ../../howto/sorting.rst:131
153162msgid ""
@@ -156,105 +165,113 @@ msgid ""
156165"that when multiple records have the same key, their original order is "
157166"preserved."
158167msgstr ""
168+ "排序保证 `稳定 "
169+ "<https://en.wikipedia.org/wiki/Sorting_algorithm#Stability>`_:等键记录保持原始顺序。"
159170
160171#: ../../howto/sorting.rst:139
161172msgid ""
162173"Notice how the two records for *blue* retain their original order so that "
163174"``('blue', 1)`` is guaranteed to precede ``('blue', 2)``."
164- msgstr ""
175+ msgstr "注意 *blue* 的两个记录是如何保序的:``('blue', 1)`` 保证先于 ``('blue', 2)``。 "
165176
166177#: ../../howto/sorting.rst:142
167178msgid ""
168179"This wonderful property lets you build complex sorts in a series of sorting "
169180"steps. For example, to sort the student data by descending *grade* and then "
170181"ascending *age*, do the *age* sort first and then sort again using *grade*:"
171182msgstr ""
183+ "这个了不起的特性使得借助一系列排序步骤构建出复杂排序成为可能。例如,要按 *grade* 降序后 *age* 升序排序学生数据,只需先用 *age* "
184+ "排序再用 *grade* 排序即可:"
172185
173186#: ../../howto/sorting.rst:150
174187msgid ""
175188"This can be abstracted out into a wrapper function that can take a list and "
176189"tuples of field and order to sort them on multiple passes."
177- msgstr ""
190+ msgstr "可抽象为包装函数,依据接收的一些字段序的元组对接收的列表做多趟排序。 "
178191
179192#: ../../howto/sorting.rst:161
180193msgid ""
181194"The `Timsort <https://en.wikipedia.org/wiki/Timsort>`_ algorithm used in "
182195"Python does multiple sorts efficiently because it can take advantage of any "
183196"ordering already present in a dataset."
184197msgstr ""
198+ "Python 中曾用的 `Timsort <https://en.wikipedia.org/wiki/Timsort>`_ "
199+ "算法借助数据集中任何已有的有序性来高效进行多种排序。"
185200
186201#: ../../howto/sorting.rst:166
187202msgid "The Old Way Using Decorate-Sort-Undecorate"
188- msgstr ""
203+ msgstr "使用装饰-排序-去装饰的旧方法 "
189204
190205#: ../../howto/sorting.rst:168
191206msgid "This idiom is called Decorate-Sort-Undecorate after its three steps:"
192- msgstr ""
207+ msgstr "装饰-排序-去装饰 (Decorate-Sort-Undecorate) 得名于它的三个步骤: "
193208
194209#: ../../howto/sorting.rst:170
195210msgid ""
196211"First, the initial list is decorated with new values that control the sort "
197212"order."
198- msgstr ""
213+ msgstr "首先,用控制排序顺序的新值装饰初始列表。 "
199214
200215#: ../../howto/sorting.rst:172
201216msgid "Second, the decorated list is sorted."
202- msgstr ""
217+ msgstr "其次,排序装饰后的列表。 "
203218
204219#: ../../howto/sorting.rst:174
205220msgid ""
206221"Finally, the decorations are removed, creating a list that contains only the"
207222" initial values in the new order."
208- msgstr ""
223+ msgstr "最后,去除装饰即得按新顺序排列的初始值的列表。 "
209224
210225#: ../../howto/sorting.rst:177
211226msgid ""
212227"For example, to sort the student data by *grade* using the DSU approach:"
213- msgstr ""
228+ msgstr "例如,用 DSU 方法按 *grade* 排序学生数据: "
214229
215230#: ../../howto/sorting.rst:184
216231msgid ""
217232"This idiom works because tuples are compared lexicographically; the first "
218233"items are compared; if they are the same then the second items are compared,"
219234" and so on."
220- msgstr ""
235+ msgstr "这方法语有效是因为元组按字典顺序进行比较,先比较第一项;如果它们相同则比较第二个项目,依此类推。 "
221236
222237#: ../../howto/sorting.rst:188
223238msgid ""
224239"It is not strictly necessary in all cases to include the index *i* in the "
225240"decorated list, but including it gives two benefits:"
226- msgstr ""
241+ msgstr "不一定在所有情况下都要在装饰列表中包含索引 *i* ,但包含它有两个好处: "
227242
228243#: ../../howto/sorting.rst:191
229244msgid ""
230245"The sort is stable -- if two items have the same key, their order will be "
231246"preserved in the sorted list."
232- msgstr ""
247+ msgstr "排序是稳定的——如果两个项具有相同的键,它们的顺序将保留在排序列表中。 "
233248
234249#: ../../howto/sorting.rst:194
235250msgid ""
236251"The original items do not have to be comparable because the ordering of the "
237252"decorated tuples will be determined by at most the first two items. So for "
238253"example the original list could contain complex numbers which cannot be "
239254"sorted directly."
240- msgstr ""
255+ msgstr "原始项目不必具有可比性,因为装饰元组的排序最多由前两项决定。 因此,例如原始列表可能包含无法直接排序的复数。 "
241256
242257#: ../../howto/sorting.rst:199
243258msgid ""
244259"Another name for this idiom is `Schwartzian transform "
245260"<https://en.wikipedia.org/wiki/Schwartzian_transform>`_\\ , after Randal L. "
246261"Schwartz, who popularized it among Perl programmers."
247262msgstr ""
263+ "这个方法的另一个名字是 Randal L. Schwartz 在 Perl 程序员中推广的 `Schwartzian transform "
264+ "<https://en.wikipedia.org/wiki/Schwartzian_transform>`_\\ 。"
248265
249266#: ../../howto/sorting.rst:203
250267msgid ""
251268"Now that Python sorting provides key-functions, this technique is not often "
252269"needed."
253- msgstr ""
270+ msgstr "既然 Python 排序提供了键函数,那么通常不需要这种技术。 "
254271
255272#: ../../howto/sorting.rst:207
256273msgid "The Old Way Using the *cmp* Parameter"
257- msgstr ""
274+ msgstr "使用 *cmp* 参数的旧方法 "
258275
259276#: ../../howto/sorting.rst:209
260277msgid ""
@@ -263,13 +280,17 @@ msgid ""
263280"arguments. Instead, all of the Py2.x versions supported a *cmp* parameter to"
264281" handle user specified comparison functions."
265282msgstr ""
283+ "本 HOWTO 中给出的许多结构都假定为 Python 2.4 或更高版本。在此之前,没有内置 :func:`sorted` , "
284+ ":meth:`list.sort` 也没有关键字参数。相反,所有 Py2.x 版本都支持 *cmp* 参数来处理用户指定的比较函数。"
266285
267286#: ../../howto/sorting.rst:214
268287msgid ""
269288"In Py3.0, the *cmp* parameter was removed entirely (as part of a larger "
270289"effort to simplify and unify the language, eliminating the conflict between "
271290"rich comparisons and the :meth:`__cmp__` magic method)."
272291msgstr ""
292+ "在 Py3.0 中, *cmp* 参数被完全删除(作为简化和统一语言努力的一部分,消除了丰富的比较与 :meth:`__cmp__` "
293+ "魔术方法之间的冲突)。"
273294
274295#: ../../howto/sorting.rst:218
275296msgid ""
@@ -278,10 +299,12 @@ msgid ""
278299"then return a negative value for less-than, return zero if they are equal, "
279300"or return a positive value for greater-than. For example, we can do:"
280301msgstr ""
302+ "在 Py2.x 中, sort "
303+ "允许一个可选函数,可以调用它来进行比较。该函数应该采用两个参数进行比较,然后返回负值为小于,如果它们相等则返回零,或者返回大于大于的正值。例如,我们可以这样做:"
281304
282305#: ../../howto/sorting.rst:228
283306msgid "Or you can reverse the order of comparison with:"
284- msgstr ""
307+ msgstr "或者你可反转比较的顺序: "
285308
286309#: ../../howto/sorting.rst:235
287310msgid ""
@@ -292,23 +315,26 @@ msgstr ""
292315
293316#: ../../howto/sorting.rst:258
294317msgid "To convert to a key function, just wrap the old comparison function:"
295- msgstr ""
318+ msgstr "要转换为键函数,只需包装旧的比较函数: "
296319
297320#: ../../howto/sorting.rst:269
298321msgid ""
299322"In Python 3.2, the :func:`functools.cmp_to_key` function was added to the "
300323":mod:`functools` module in the standard library."
301324msgstr ""
325+ "在 Python 3.2 中, :func:`functools.cmp_to_key` 函数被添加到标准库中的 :mod:`functools` "
326+ "模块中。"
302327
303328#: ../../howto/sorting.rst:273
304329msgid "Odd and Ends"
305- msgstr ""
330+ msgstr "其它 "
306331
307332#: ../../howto/sorting.rst:275
308333msgid ""
309334"For locale aware sorting, use :func:`locale.strxfrm` for a key function or "
310335":func:`locale.strcoll` for a comparison function."
311336msgstr ""
337+ "对于区域相关的排序,请使用 :func:`locale.strxfrm` 作为键函数,或者 :func:`locale.strcoll` 作为比较函数。"
312338
313339#: ../../howto/sorting.rst:278
314340msgid ""
@@ -317,6 +343,8 @@ msgid ""
317343"simulated without the parameter by using the builtin :func:`reversed` "
318344"function twice:"
319345msgstr ""
346+ "*reverse* 参数仍然保持排序稳定性(因此具有相等键的记录保留原始顺序)。 有趣的是,通过使用内置的 :func:`reversed` "
347+ "函数两次,可以在没有参数的情况下模拟该效果:"
320348
321349#: ../../howto/sorting.rst:290
322350msgid ""
@@ -330,11 +358,13 @@ msgid ""
330358"However, note that ``<`` can fall back to using :meth:`__gt__` if "
331359":meth:`__lt__` is not implemented (see :func:`object.__lt__`)."
332360msgstr ""
361+ "然而,请注意,如果 :meth:`__gt__` 没有实现,``<`` 可以退回到使用 :meth:`__lt__` (见 "
362+ ":func:`object.__lt__` )。"
333363
334364#: ../../howto/sorting.rst:301
335365msgid ""
336366"Key functions need not depend directly on the objects being sorted. A key "
337367"function can also access external resources. For instance, if the student "
338368"grades are stored in a dictionary, they can be used to sort a separate list "
339369"of student names:"
340- msgstr ""
370+ msgstr "键函数不需要直接依赖于被排序的对象。键函数还可以访问外部资源。例如,如果学生成绩存储在字典中,则可以使用它们对单独的学生姓名列表进行排序: "
0 commit comments