-
-
Notifications
You must be signed in to change notification settings - Fork 224
Expand file tree
/
Copy pathsorting.po
More file actions
390 lines (338 loc) · 15.8 KB
/
sorting.po
File metadata and controls
390 lines (338 loc) · 15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001-2022, Python Software Foundation
# This file is distributed under the same license as the Python package.
#
# Translators:
# Ching-Lung Chuang, 2015
msgid ""
msgstr ""
"Project-Id-Version: Python 3.12\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-24 00:03+0000\n"
"PO-Revision-Date: 2023-08-12 15:09+0800\n"
"Last-Translator: Adrian Liaw <adrianliaw2000@gmail.com>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
"Language: zh_TW\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
#: ../../howto/sorting.rst:4
msgid "Sorting HOW TO"
msgstr "如何排序"
#: ../../howto/sorting.rst:0
msgid "Author"
msgstr "作者"
#: ../../howto/sorting.rst:6
msgid "Andrew Dalke and Raymond Hettinger"
msgstr "Andrew Dalke 和 Raymond Hettinger"
#: ../../howto/sorting.rst:0
msgid "Release"
msgstr "發佈版本"
#: ../../howto/sorting.rst:7
msgid "0.1"
msgstr "0.1"
#: ../../howto/sorting.rst:10
msgid ""
"Python lists have a built-in :meth:`list.sort` method that modifies the list "
"in-place. There is also a :func:`sorted` built-in function that builds a "
"new sorted list from an iterable."
msgstr ""
"Python 的串列有一個內建的 :meth:`list.sort` 方法可以原地 (in-place) 排序該串"
"列,也有一個內建的 :func:`sorted` 函式可以排序可疊代物件 (iterable) 並建立一"
"個新的排序好的串列。"
#: ../../howto/sorting.rst:14
msgid ""
"In this document, we explore the various techniques for sorting data using "
"Python."
msgstr "在這份文件裡,我們探索使用 Python 排序資料的各種方法。"
#: ../../howto/sorting.rst:18
msgid "Sorting Basics"
msgstr "基礎排序"
#: ../../howto/sorting.rst:20
msgid ""
"A simple ascending sort is very easy: just call the :func:`sorted` function. "
"It returns a new sorted list:"
msgstr ""
"單純的升冪排序很容易做到:只要呼叫 :func:`sorted` 函式,它會回傳一個新的串"
"列:"
#: ../../howto/sorting.rst:28
msgid ""
"You can also use the :meth:`list.sort` method. It modifies the list in-place "
"(and returns ``None`` to avoid confusion). Usually it's less convenient "
"than :func:`sorted` - but if you don't need the original list, it's slightly "
"more efficient."
msgstr ""
"你也可以使用 :meth:`list.sort` 方法,它會原地排序串列(並回傳 ``None`` 以避免"
"混淆)。它通常會比 :func:`sorted` 來得不方便——但如果你不需要保留原始串列的"
"話,它會稍微有效率一點。"
#: ../../howto/sorting.rst:40
msgid ""
"Another difference is that the :meth:`list.sort` method is only defined for "
"lists. In contrast, the :func:`sorted` function accepts any iterable."
msgstr ""
"另一個差異是 :meth:`list.sort` 方法只有定義在串列上,而 :func:`sorted` 函式可"
"以接受任何可疊代物件。"
#: ../../howto/sorting.rst:49
msgid "Key Functions"
msgstr "鍵函式 (key functions)"
#: ../../howto/sorting.rst:51
msgid ""
"Both :meth:`list.sort` and :func:`sorted` have a *key* parameter to specify "
"a function (or other callable) to be called on each list element prior to "
"making comparisons."
msgstr ""
":meth:`list.sort` 和 :func:`sorted` 都有一個參數 *key* 可以指定一個函式(或其"
"它可呼叫物件 (callable)),這個函式會在每個串列元素做比較前被呼叫。"
#: ../../howto/sorting.rst:55
msgid "For example, here's a case-insensitive string comparison:"
msgstr "例如這裡有一個不區分大小寫的字串比對:"
#: ../../howto/sorting.rst:62
msgid ""
"The value of the *key* parameter should be a function (or other callable) "
"that takes a single argument and returns a key to use for sorting purposes. "
"This technique is fast because the key function is called exactly once for "
"each input record."
msgstr ""
"參數 *key* 的值必須是一個函式(或其它可呼叫物件),且這個函式接受單一引數並回"
"傳一個用來排序的鍵。因為對每個輸入來說鍵函式只會被呼叫一次,所以這個做法是快"
"速的。"
#: ../../howto/sorting.rst:67
msgid ""
"A common pattern is to sort complex objects using some of the object's "
"indices as keys. For example:"
msgstr ""
"一個常見的模式是在排序複雜物件的時候使用一部分物件的索引值當作鍵,例如:"
#: ../../howto/sorting.rst:80
msgid ""
"The same technique works for objects with named attributes. For example:"
msgstr "相同的做法也適用在有命名屬性的物件,例如:"
#: ../../howto/sorting.rst:101
msgid "Operator Module Functions"
msgstr "Operator 模組的函式"
#: ../../howto/sorting.rst:103
msgid ""
"The key-function patterns shown above are very common, so Python provides "
"convenience functions to make accessor functions easier and faster. The :mod:"
"`operator` module has :func:`~operator.itemgetter`, :func:`~operator."
"attrgetter`, and a :func:`~operator.methodcaller` function."
msgstr ""
"上述的鍵函式模式非常常見,所以 Python 提供了方便的函式讓物件存取更簡單且快"
"速。:mod:`operator` 模組裡有 :func:`~operator.itemgetter`、:func:"
"`~operator.attrgetter` 及 :func:`~operator.methodcaller` 函式可以使用。"
#: ../../howto/sorting.rst:108
msgid "Using those functions, the above examples become simpler and faster:"
msgstr "使用這些函式讓上面的範例變得更簡單且快速:"
#: ../../howto/sorting.rst:120
msgid ""
"The operator module functions allow multiple levels of sorting. For example, "
"to sort by *grade* then by *age*:"
msgstr ""
"operator 模組的函式允許多層的排序,例如先用 *grade* 排序再用 *age* 排序:"
#: ../../howto/sorting.rst:132
msgid "Ascending and Descending"
msgstr "升冪與降冪"
#: ../../howto/sorting.rst:134
msgid ""
"Both :meth:`list.sort` and :func:`sorted` accept a *reverse* parameter with "
"a boolean value. This is used to flag descending sorts. For example, to get "
"the student data in reverse *age* order:"
msgstr ""
":meth:`list.sort` 和 :func:`sorted` 都有一個 boolean 參數 *reverse* 用來表示"
"是否要降冪排序。例如將學生資料依據 *age* 做降冪排序:"
#: ../../howto/sorting.rst:147
msgid "Sort Stability and Complex Sorts"
msgstr "排序穩定性與複合排序"
#: ../../howto/sorting.rst:149
msgid ""
"Sorts are guaranteed to be `stable <https://en.wikipedia.org/wiki/"
"Sorting_algorithm#Stability>`_\\. That means that when multiple records have "
"the same key, their original order is preserved."
msgstr ""
"排序保證是\\ `穩定的 <https://en.wikipedia.org/wiki/"
"Sorting_algorithm#Stability>`_\\ ,意思是當有多筆資料有相同的鍵,它們會維持原"
"來的順序。"
#: ../../howto/sorting.rst:159
msgid ""
"Notice how the two records for *blue* retain their original order so that "
"``('blue', 1)`` is guaranteed to precede ``('blue', 2)``."
msgstr ""
"可以注意到有兩筆資料的鍵都是 *blue*,它們會維持本來的順序,即 ``('blue', "
"1)`` 保證在 ``('blue', 2)`` 前面。"
#: ../../howto/sorting.rst:162
msgid ""
"This wonderful property lets you build complex sorts in a series of sorting "
"steps. For example, to sort the student data by descending *grade* and then "
"ascending *age*, do the *age* sort first and then sort again using *grade*:"
msgstr ""
"這個美妙的特性讓你可以用一連串的排序來作出複合排序。例如對學生資料用 *grade* "
"做降冪排序再用 *age* 做升冪排序,你可以先用 *age* 排序一遍再用 *grade* 排序一"
"遍:"
#: ../../howto/sorting.rst:172
msgid ""
"This can be abstracted out into a wrapper function that can take a list and "
"tuples of field and order to sort them on multiple passes."
msgstr ""
"這可以抽出一個包裝函式 (wrapper function),接受一個串列及多個欄位及升降冪的元"
"組為引數,來對這個串列排序多遍。"
#: ../../howto/sorting.rst:185
msgid ""
"The `Timsort <https://en.wikipedia.org/wiki/Timsort>`_ algorithm used in "
"Python does multiple sorts efficiently because it can take advantage of any "
"ordering already present in a dataset."
msgstr ""
"Python 裡使用的 `Timsort <https://en.wikipedia.org/wiki/Timsort>`_ 演算法,因"
"為能利用資料集裡已經有的順序,可以有效率地做多次排序。"
#: ../../howto/sorting.rst:190
msgid "Decorate-Sort-Undecorate"
msgstr "裝飾-排序-移除裝飾 (decorate-sort-undecorate)"
#: ../../howto/sorting.rst:192
msgid "This idiom is called Decorate-Sort-Undecorate after its three steps:"
msgstr "這個用語的來源是因為它做了以下三件事情:"
#: ../../howto/sorting.rst:194
msgid ""
"First, the initial list is decorated with new values that control the sort "
"order."
msgstr "首先,原始串列會裝飾 (decorated) 上新的值用來控制排序的順序。"
#: ../../howto/sorting.rst:196
msgid "Second, the decorated list is sorted."
msgstr "接下來,排序裝飾過的串列。"
#: ../../howto/sorting.rst:198
msgid ""
"Finally, the decorations are removed, creating a list that contains only the "
"initial values in the new order."
msgstr "最後,裝飾會被移除,並以新的順序產生一個只包含原始值的串列。"
#: ../../howto/sorting.rst:201
msgid ""
"For example, to sort the student data by *grade* using the DSU approach:"
msgstr "例如用上面說的方式來以 *grade* 排序學生資料:"
#: ../../howto/sorting.rst:208
msgid ""
"This idiom works because tuples are compared lexicographically; the first "
"items are compared; if they are the same then the second items are compared, "
"and so on."
msgstr ""
"這個方式會有效是因為元組是依照字典順序 (lexicographically) 來比較,先比較第"
"一個項目,如果一樣再比較第二個項目,並依此類推。"
#: ../../howto/sorting.rst:212
msgid ""
"It is not strictly necessary in all cases to include the index *i* in the "
"decorated list, but including it gives two benefits:"
msgstr ""
"在所有情況下都把索引 *i* 加入已裝飾的串列並不是絕對需要的,但這樣做會有兩個好"
"處:"
#: ../../howto/sorting.rst:215
msgid ""
"The sort is stable -- if two items have the same key, their order will be "
"preserved in the sorted list."
msgstr ""
"排序會是穩定的 -- 如果兩個項目有相同的鍵,它們在排序好的串列中會保持原來的順"
"序。"
#: ../../howto/sorting.rst:218
msgid ""
"The original items do not have to be comparable because the ordering of the "
"decorated tuples will be determined by at most the first two items. So for "
"example the original list could contain complex numbers which cannot be "
"sorted directly."
msgstr ""
"原始項目不需要是可以比較的,因為最多只會用到前兩個項目就能決定裝飾過的元組的"
"順序。例如原始串列可以包含不能直接用來排序的複數。"
#: ../../howto/sorting.rst:223
msgid ""
"Another name for this idiom is `Schwartzian transform <https://en.wikipedia."
"org/wiki/Schwartzian_transform>`_\\, after Randal L. Schwartz, who "
"popularized it among Perl programmers."
msgstr ""
"這個用語的另一個名字是 `Schwartzian transform <https://en.wikipedia.org/wiki/"
"Schwartzian_transform>`_\\ ,是由於 Randal L. Schwartz 讓這個方法在 Perl 程式"
"設計師間普及。"
#: ../../howto/sorting.rst:227
msgid ""
"Now that Python sorting provides key-functions, this technique is not often "
"needed."
msgstr "而因為 Python 的排序提供了鍵函式,已經不太需要用到這個方法了。"
#: ../../howto/sorting.rst:230
msgid "Comparison Functions"
msgstr "比較函式 (comparison functions)"
#: ../../howto/sorting.rst:232
msgid ""
"Unlike key functions that return an absolute value for sorting, a comparison "
"function computes the relative ordering for two inputs."
msgstr "不像鍵函式回傳一個用來排序的值,比較函式計算兩個輸入間的相對順序。"
#: ../../howto/sorting.rst:235
msgid ""
"For example, a `balance scale <https://upload.wikimedia.org/wikipedia/"
"commons/1/17/Balance_à_tabac_1850.JPG>`_ compares two samples giving a "
"relative ordering: lighter, equal, or heavier. Likewise, a comparison "
"function such as ``cmp(a, b)`` will return a negative value for less-than, "
"zero if the inputs are equal, or a positive value for greater-than."
msgstr ""
"例如\\ `天秤 <https://upload.wikimedia.org/wikipedia/commons/1/17/"
"Balance_à_tabac_1850.JPG>`_\\ 比較兩邊樣本並給出相對的順序:較輕、相同或較"
"重。同樣地,像是 ``cmp(a, b)`` 這樣的比較函式會回傳負數代表小於、0 代表輸入相"
"同或正數代表大於。"
#: ../../howto/sorting.rst:242
msgid ""
"It is common to encounter comparison functions when translating algorithms "
"from other languages. Also, some libraries provide comparison functions as "
"part of their API. For example, :func:`locale.strcoll` is a comparison "
"function."
msgstr ""
"當從其它語言翻譯演算法的時候常看到比較函式。有些函式庫也會提供比較函式作為其 "
"API 的一部份,例如 :func:`locale.strcoll` 就是一個比較函式。"
#: ../../howto/sorting.rst:246
msgid ""
"To accommodate those situations, Python provides :class:`functools."
"cmp_to_key` to wrap the comparison function to make it usable as a key "
"function::"
msgstr ""
"為了滿足這些情境,Python 提供 :class:`functools.cmp_to_key` 來包裝比較函式,"
"讓其可以當作鍵函式來使用: ::"
#: ../../howto/sorting.rst:253
msgid "Odds and Ends"
msgstr "雜項說明"
#: ../../howto/sorting.rst:255
msgid ""
"For locale aware sorting, use :func:`locale.strxfrm` for a key function or :"
"func:`locale.strcoll` for a comparison function. This is necessary because "
"\"alphabetical\" sort orderings can vary across cultures even if the "
"underlying alphabet is the same."
msgstr ""
"要處理能理解本地語系 (locale aware) 的排序可以使用 :func:`locale.strxfrm` 當"
"作鍵函式,或 :func:`locale.strcoll` 當作比較函式。這樣做是必要的,因為在不同"
"文化中就算是相同的字母,按「字母順序」排序的結果也各不相同。"
#: ../../howto/sorting.rst:260
msgid ""
"The *reverse* parameter still maintains sort stability (so that records with "
"equal keys retain the original order). Interestingly, that effect can be "
"simulated without the parameter by using the builtin :func:`reversed` "
"function twice:"
msgstr ""
"*reverse* 參數依然會維持排序穩定性(即有相同鍵的資料會保持原來順序)。有趣的"
"是,不加這個參數也可以模擬這個效果,只要使用內建的 :func:`reversed` 函式兩"
"次:"
#: ../../howto/sorting.rst:274
msgid ""
"The sort routines use ``<`` when making comparisons between two objects. So, "
"it is easy to add a standard sort order to a class by defining an :meth:"
"`~object.__lt__` method:"
msgstr ""
"排序時會使用 ``<`` 來比較兩個物件,因此要在類別裡面加入排序順序比較規則是簡單"
"的,只要透過定義 :meth:`~object.__lt__` 方法:"
#: ../../howto/sorting.rst:284
msgid ""
"However, note that ``<`` can fall back to using :meth:`~object.__gt__` if :"
"meth:`~object.__lt__` is not implemented (see :func:`object.__lt__`)."
msgstr ""
"然而,需要注意如果沒有實作 :meth:`~object.__lt__`,則 ``<`` 會退而使用 :meth:"
"`~object.__gt__`\\ (參見 :func:`object.__lt__`)。"
#: ../../howto/sorting.rst:287
msgid ""
"Key functions need not depend directly on the objects being sorted. A key "
"function can also access external resources. For instance, if the student "
"grades are stored in a dictionary, they can be used to sort a separate list "
"of student names:"
msgstr ""
"鍵函式不需要直接依賴用來排序的物件。鍵函式也可以存取外部資源,例如如果學生成"
"績儲存在字典裡,它可以用來排序一個單獨的學生姓名串列:"