@@ -9,7 +9,7 @@ msgstr ""
9
9
"Project-Id-Version : Python 3.12\n "
10
10
"Report-Msgid-Bugs-To : \n "
11
11
"POT-Creation-Date : 2023-07-24 00:03+0000\n "
12
- "PO-Revision-Date : 2018-05-23 14:37+0000 \n "
12
+ "PO-Revision-Date : 2023-08-09 18:16+0800 \n "
13
13
"
Last-Translator :
Adrian Liaw <[email protected] >\n "
14
14
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
15
15
"tw)\n "
@@ -45,12 +45,15 @@ msgid ""
45
45
"in-place. There is also a :func:`sorted` built-in function that builds a "
46
46
"new sorted list from an iterable."
47
47
msgstr ""
48
+ "Python 的串列有一個內建的 :meth:`list.sort` 方法可以原地排序該串列,也有一個"
49
+ "內建的 :func:`sorted` 函式可以排序可疊代物件 (iterable) 並創建一個新的排序好"
50
+ "的串列。"
48
51
49
52
#: ../../howto/sorting.rst:14
50
53
msgid ""
51
54
"In this document, we explore the various techniques for sorting data using "
52
55
"Python."
53
- msgstr "在此文件,我們使用Python進行各種方式排序資料 "
56
+ msgstr "在這份文件裡,我們探索使用 Python 排序資料的各種方法。 "
54
57
55
58
#: ../../howto/sorting.rst:18
56
59
msgid "Sorting Basics"
@@ -61,6 +64,8 @@ msgid ""
61
64
"A simple ascending sort is very easy: just call the :func:`sorted` function. "
62
65
"It returns a new sorted list:"
63
66
msgstr ""
67
+ "單純的升冪排序很容易做到:只要呼叫 :func:`sorted` 函式,它會回傳一個新的串"
68
+ "列:"
64
69
65
70
#: ../../howto/sorting.rst:28
66
71
msgid ""
@@ -69,27 +74,34 @@ msgid ""
69
74
"than :func:`sorted` - but if you don't need the original list, it's slightly "
70
75
"more efficient."
71
76
msgstr ""
77
+ "你也可以使用 :meth:`list.sort` 方法,它會原地排序串列(並回傳 ``None`` 以避免"
78
+ "混淆)。它通常會比 :func:`sorted` 來得不方便——但如果你不需要保留原始串列的"
79
+ "話,它會稍微有效率一點。"
72
80
73
81
#: ../../howto/sorting.rst:40
74
82
msgid ""
75
83
"Another difference is that the :meth:`list.sort` method is only defined for "
76
84
"lists. In contrast, the :func:`sorted` function accepts any iterable."
77
85
msgstr ""
86
+ "另一個差異是 :meth:`list.sort` 方法只有定義在串列上,而 :func:`sorted` 函式可"
87
+ "以接受任何可疊代物件。"
78
88
79
89
#: ../../howto/sorting.rst:49
80
90
msgid "Key Functions"
81
- msgstr ""
91
+ msgstr "鍵函式 (key functions) "
82
92
83
93
#: ../../howto/sorting.rst:51
84
94
msgid ""
85
95
"Both :meth:`list.sort` and :func:`sorted` have a *key* parameter to specify "
86
96
"a function (or other callable) to be called on each list element prior to "
87
97
"making comparisons."
88
98
msgstr ""
99
+ ":meth:`list.sort` 和 :func:`sorted` 都有一個參數 *key* 可以指定一個函式(或其"
100
+ "它可呼叫物件 (callable)),這個函式會在每個串列元素做比較前被呼叫。"
89
101
90
102
#: ../../howto/sorting.rst:55
91
103
msgid "For example, here's a case-insensitive string comparison:"
92
- msgstr ""
104
+ msgstr "例如這裡有一個不區分大小寫的字串比對: "
93
105
94
106
#: ../../howto/sorting.rst:62
95
107
msgid ""
@@ -98,21 +110,25 @@ msgid ""
98
110
"This technique is fast because the key function is called exactly once for "
99
111
"each input record."
100
112
msgstr ""
113
+ "參數 *key* 的值必須是一個函式(或其它可呼叫物件),且這個函式接受單一引數並回"
114
+ "傳一個用來排序的鍵。因為對每個輸入來說鍵函式只會被呼叫一次,所以這個做法是快"
115
+ "速的。"
101
116
102
117
#: ../../howto/sorting.rst:67
103
118
msgid ""
104
119
"A common pattern is to sort complex objects using some of the object's "
105
120
"indices as keys. For example:"
106
121
msgstr ""
122
+ "一個常見的模式是在排序複雜物件的時候使用一部分物件的索引值當作鍵,例如:"
107
123
108
124
#: ../../howto/sorting.rst:80
109
125
msgid ""
110
126
"The same technique works for objects with named attributes. For example:"
111
- msgstr ""
127
+ msgstr "相同的做法也適用在有命名屬性的物件,例如: "
112
128
113
129
#: ../../howto/sorting.rst:101
114
130
msgid "Operator Module Functions"
115
- msgstr ""
131
+ msgstr "Operator 模組的函式 "
116
132
117
133
#: ../../howto/sorting.rst:103
118
134
msgid ""
@@ -121,16 +137,20 @@ msgid ""
121
137
"`operator` module has :func:`~operator.itemgetter`, :func:`~operator."
122
138
"attrgetter`, and a :func:`~operator.methodcaller` function."
123
139
msgstr ""
140
+ "上述的鍵函式模式非常常見,所以 Python 提供了方便的函式讓物件存取更簡單且快"
141
+ "速。\\ :mod:`operator` 模組裡有 :func:`~operator.itemgetter`\\ 、\\ :func:"
142
+ "`~operator.attrgetter` 及 :func:`~operator.methodcaller` 函式可以使用。"
124
143
125
144
#: ../../howto/sorting.rst:108
126
145
msgid "Using those functions, the above examples become simpler and faster:"
127
- msgstr ""
146
+ msgstr "使用這些函式讓上面的範例變得更簡單且快速: "
128
147
129
148
#: ../../howto/sorting.rst:120
130
149
msgid ""
131
150
"The operator module functions allow multiple levels of sorting. For example, "
132
151
"to sort by *grade* then by *age*:"
133
152
msgstr ""
153
+ "operator 模組的函式允許多層的排序,例如先用 *grade* 排序再用 *age* 排序:"
134
154
135
155
#: ../../howto/sorting.rst:132
136
156
msgid "Ascending and Descending"
@@ -142,43 +162,57 @@ msgid ""
142
162
"a boolean value. This is used to flag descending sorts. For example, to get "
143
163
"the student data in reverse *age* order:"
144
164
msgstr ""
165
+ ":meth:`list.sort` 和 :func:`sorted` 都有一個 boolean 參數 *reverse* 用來表示"
166
+ "是否要降冪排序。例如將學生資料依據 *age* 做降冪排序:"
145
167
146
168
#: ../../howto/sorting.rst:147
147
169
msgid "Sort Stability and Complex Sorts"
148
- msgstr ""
170
+ msgstr "排序穩定性與複合排序 "
149
171
150
172
#: ../../howto/sorting.rst:149
151
173
msgid ""
152
174
"Sorts are guaranteed to be `stable <https://en.wikipedia.org/wiki/"
153
175
"Sorting_algorithm#Stability>`_\\ . That means that when multiple records have "
154
176
"the same key, their original order is preserved."
155
177
msgstr ""
178
+ "排序保證是\\ `穩定的 <https://en.wikipedia.org/wiki/"
179
+ "Sorting_algorithm#Stability>`_\\ ,意思是當有多筆資料有相同的鍵,它們會維持原"
180
+ "來的順序。"
156
181
157
182
#: ../../howto/sorting.rst:159
158
183
msgid ""
159
184
"Notice how the two records for *blue* retain their original order so that "
160
185
"``('blue', 1)`` is guaranteed to precede ``('blue', 2)``."
161
186
msgstr ""
187
+ "可以注意到有兩筆資料的鍵都是 *blue*,它們會維持本來的順序,即 ``('blue', "
188
+ "1)`` 保證在 ``('blue', 2)`` 前面。"
162
189
163
190
#: ../../howto/sorting.rst:162
164
191
msgid ""
165
192
"This wonderful property lets you build complex sorts in a series of sorting "
166
193
"steps. For example, to sort the student data by descending *grade* and then "
167
194
"ascending *age*, do the *age* sort first and then sort again using *grade*:"
168
195
msgstr ""
196
+ "這個美妙的特性讓你可以用一連串的排序來作出複合排序。例如對學生資料用 *grade* "
197
+ "做降冪排序再用 *age* 做升冪排序,你可以先用 *age* 排序一遍再用 *grade* 排序一"
198
+ "遍:"
169
199
170
200
#: ../../howto/sorting.rst:172
171
201
msgid ""
172
202
"This can be abstracted out into a wrapper function that can take a list and "
173
203
"tuples of field and order to sort them on multiple passes."
174
204
msgstr ""
205
+ "這可以抽出一個包裝函式 (wrapper function),接受一個串列及多個欄位及升降冪的元"
206
+ "組為引數,來對這個串列排序多遍。"
175
207
176
208
#: ../../howto/sorting.rst:185
177
209
msgid ""
178
210
"The `Timsort <https://en.wikipedia.org/wiki/Timsort>`_ algorithm used in "
179
211
"Python does multiple sorts efficiently because it can take advantage of any "
180
212
"ordering already present in a dataset."
181
213
msgstr ""
214
+ "Python 裡使用的 `Timsort <https://en.wikipedia.org/wiki/Timsort>`_ 演算法,因"
215
+ "為能利用資料集裡已經有的順序,可以有效率地做多次排序。"
182
216
183
217
#: ../../howto/sorting.rst:190
184
218
msgid "Decorate-Sort-Undecorate"
0 commit comments