Index: Doc/howto/sorting.rst =================================================================== --- Doc/howto/sorting.rst (révision 87951) +++ Doc/howto/sorting.rst (copie de travail) @@ -7,7 +7,7 @@ :Release: 0.1 -Python lists have a built-in :meth:`list.sort` method that modifies the list +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. @@ -23,7 +23,7 @@ >>> sorted([5, 2, 3, 1, 4]) [1, 2, 3, 4, 5] -You can also use the :meth:`list.sort` method of a list. It modifies the list +You can also use the :meth:`~list.sort` method of a list. 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. @@ -33,7 +33,7 @@ >>> a [1, 2, 3, 4, 5] -Another difference is that the :meth:`list.sort` method is only defined for +Another difference is that the :meth:`~list.sort` method is only defined for lists. In contrast, the :func:`sorted` function accepts any iterable. >>> sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'}) @@ -87,9 +87,9 @@ ========================= The key-function patterns shown above are very common, so Python provides -convenience functions to make accessor functions easier and faster. The operator -module has :func:`operator.itemgetter`, :func:`operator.attrgetter`, and -an :func:`operator.methodcaller` function. +convenience functions to make accessor functions easier and faster. The :mod:`operator` +module provides the :func:`~operator.itemgetter`, :func:`~operator.attrgetter`, and +:func:`~operator.methodcaller` functions. Using those functions, the above examples become simpler and faster: @@ -127,7 +127,7 @@ ================================ Sorts are guaranteed to be `stable -`_\. That means that +`_. That means that when multiple records have the same key, their original order is preserved. >>> data = [('red', 1), ('blue', 1), ('red', 2), ('blue', 2)] @@ -184,7 +184,7 @@ directly. Another name for this idiom is -`Schwartzian transform `_\, +`Schwartzian transform `_, after Randal L. Schwartz, who popularized it among Perl programmers. Now that Python sorting provides key-functions, this technique is not often needed. @@ -247,8 +247,8 @@ >>> sorted([5, 2, 4, 1, 3], key=cmp_to_key(reverse_numeric)) [5, 4, 3, 2, 1] -In Python 3.2, the :func:`functools.cmp_to_key` function was added to the -functools module in the standard library. +In Python 3.2, the :func:`~functools.cmp_to_key` function was added to the +:mod:`functools` module in the standard library. Odd and Ends ============