[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/python/python-docs-zh-tw/library/string/howto/sorting.po [Back]  [Original]

# 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 \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 `_\\. That means that when multiple records have "
"the same key, their original order is preserved."
msgstr ""
"\\ ` `_\\ "
""

#: ../../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 `_ algorithm used in "
"Python does multiple sorts efficiently because it can take advantage of any "
"ordering already present in a dataset."
msgstr ""
"Python  `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 `_\\, after Randal L. Schwartz, who "
"popularized it among Perl programmers."
msgstr ""
" `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 `_ 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 ""
"\\ ` `_\\ "
" ``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 ``

Web Proxy Viewer  |  New URL  |  Original Page