8000 GH-91415: Mention alphabetical sort ordering in the Sorting HOWTO by rhettinger · Pull Request #98336 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

GH-91415: Mention alphabetical sort ordering in the Sorting HOWTO #98336

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Oct 16, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Working and grammar tweaks.
  • Loading branch information
rhettinger committed Oct 16, 2022
commit f5dece4b6b8417781af29377a08ff2a79b79fb41
15 changes: 7 additions & 8 deletions Doc/howto/sorting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -234,18 +234,17 @@ a comparison function computes the relative ordering for two inputs.

For example, a `balance scale
<https://upload.wikimedia.org/wikipedia/commons/1/17/Balance_à_tabac_1850.JPG>`_
compares two samples giving a relative ordering of lighter, heavier, or
equal. Likewise, comparison function ``cmp(a, b)`` returns a negative
value for less-than, a positive value for greater-than, or zero if the
inputs are equal.
compares two samples giving a relative ordering: lighter, equal, or heavier.
Likewise, a comparison functions such as ``cmp(a, b)`` will a negative value for
less-than, zero if the inputs are equal, or a positive value for greater-than.

It is common to find comparison functions when translating algorithms
from other languages. And sometimes, libraries provide comparison
functions. For example, :func:`locale.strcoll` is a comparison function.
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.

To accommodate those situations, Python provides
:class:`functools.cmp_to_key` to wrap the comparison function
making it usable as a key function::
to make it usable as a key function::

sorted(words, key=cmp_to_key(strcoll)

Expand Down
0