[Python-checkins] cpython (3.5): remove cruft from Schwarzian transform section

benjamin.peterson python-checkins at python.org
Fri May 27 01:57:07 EDT 2016


https://hg.python.org/cpython/rev/f4c5f63801c3
changeset:   101515:f4c5f63801c3
branch:      3.5
parent:      101512:bb007a5a7291
user:        Benjamin Peterson <benjamin at python.org>
date:        Thu May 26 22:55:49 2016 -0700
summary:
  remove cruft from Schwarzian transform section

files:
  Doc/faq/programming.rst |  31 +----------------------------
  1 files changed, 1 insertions(+), 30 deletions(-)


diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1312,40 +1312,11 @@
 
 The technique, attributed to Randal Schwartz of the Perl community, sorts the
 elements of a list by a metric which maps each element to its "sort value". In
-Python, just use the ``key`` argument for the ``sort()`` method::
+Python, use the ``key`` argument for the :func:`sort()` function::
 
    Isorted = L[:]
    Isorted.sort(key=lambda s: int(s[10:15]))
 
-The ``key`` argument is new in Python 2.4, for older versions this kind of
-sorting is quite simple to do with list comprehensions.  To sort a list of
-strings by their uppercase values::
-
-  tmp1 = [(x.upper(), x) for x in L]  # Schwartzian transform
-  tmp1.sort()
-  Usorted = [x[1] for x in tmp1]
-
-To sort by the integer value of a subfield extending from positions 10-15 in
-each string::
-
-  tmp2 = [(int(s[10:15]), s) for s in L]  # Schwartzian transform
-  tmp2.sort()
-  Isorted = [x[1] for x in tmp2]
-
-For versions prior to 3.0, Isorted may also be computed by ::
-
-   def intfield(s):
-       return int(s[10:15])
-
-   def Icmp(s1, s2):
-       return cmp(intfield(s1), intfield(s2))
-
-   Isorted = L[:]
-   Isorted.sort(Icmp)
-
-but since this method calls ``intfield()`` many times for each element of L, it
-is slower than the Schwartzian Transform.
-
 
 How can I sort one list by values from another list?
 ----------------------------------------------------

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list