diff options
| author | Raymond Hettinger <python@rcn.com> | 2003-12-17 20:43:33 +0000 | 
|---|---|---|
| committer | Raymond Hettinger <python@rcn.com> | 2003-12-17 20:43:33 +0000 | 
| commit | 64958a15d7c03efdc3d2eddf247666e18d1fd910 (patch) | |
| tree | bc135ae082f8635fa858b81f52f141d7ffbd4c78 /Doc | |
| parent | df38ea9c29a431602704c6bd45ca7417225a61c4 (diff) | |
| download | cpython-git-64958a15d7c03efdc3d2eddf247666e18d1fd910.tar.gz | |
Guido grants a Christmas wish:
  sorted() becomes a regular function instead of a classmethod.
Diffstat (limited to 'Doc')
| -rw-r--r-- | Doc/lib/libfuncs.tex | 9 | ||||
| -rw-r--r-- | Doc/lib/libitertools.tex | 2 | ||||
| -rw-r--r-- | Doc/lib/libstdtypes.tex | 13 | ||||
| -rw-r--r-- | Doc/whatsnew/whatsnew24.tex | 22 | 
4 files changed, 24 insertions, 22 deletions
diff --git a/Doc/lib/libfuncs.tex b/Doc/lib/libfuncs.tex index dc9f344481..99c586b871 100644 --- a/Doc/lib/libfuncs.tex +++ b/Doc/lib/libfuncs.tex @@ -886,6 +886,15 @@ class C(object):    \samp{a[start:stop, i]}.  \end{funcdesc} +\begin{funcdesc}{sorted(\var{iterable}\optional{, \var{cmp}=None +                                      \optional{, \var{key}=None +                                      \optional{, \var{reverse}=False}}})} +  Return a new sorted list from the items in \var{iterable}. +  The optional arguments \var{cmp}, \var{key}, and \var{reverse} +  have the same meaning as those for the \method{list.sort()} method. +  \versionadded{2.4}     +\end{funcdesc} +  \begin{funcdesc}{staticmethod}{function}    Return a static method for \var{function}. diff --git a/Doc/lib/libitertools.tex b/Doc/lib/libitertools.tex index 59fb1852ad..a85e048029 100644 --- a/Doc/lib/libitertools.tex +++ b/Doc/lib/libitertools.tex @@ -398,7 +398,7 @@ Samuele  # Show a dictionary sorted and grouped by value  >>> from operator import itemgetter  >>> d = dict(a=1, b=2, c=1, d=2, e=1, f=2, g=3) ->>> di = list.sorted(d.iteritems(), key=itemgetter(1)) +>>> di = sorted(d.iteritems(), key=itemgetter(1))  >>> for k, g in groupby(di, key=itemgetter(1)):  ...     print k, map(itemgetter(0), g)  ... diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex index 8b6b194522..6e38222a23 100644 --- a/Doc/lib/libstdtypes.tex +++ b/Doc/lib/libstdtypes.tex @@ -988,9 +988,6 @@ The following operations are defined on mutable sequence types (where    \lineiii{\var{s}.sort(\optional{\var{cmp}=None\optional{, \var{key}=None                          \optional{, \var{reverse}=False}}})}  	{sort the items of \var{s} in place}{(7), (8), (9), (10)} -  \lineiii{\var{s}.sorted(\var{iterable}\optional{, \var{cmp}=None\optional{, \var{key}=None -                        \optional{, \var{reverse}=False}}})} -	{return a new sorted list from the items in \var{iterable}}{(8), (9), (11)}       \end{tableiii}  \indexiv{operations on}{mutable}{sequence}{types}  \indexiii{operations on}{sequence}{types} @@ -1040,8 +1037,8 @@ Notes:    list.  To remind you that they operate by side effect, they don't return    the sorted or reversed list. -\item[(8)] The \method{sort()} and \method{sorted()} methods take optional -  arguments for controlling the comparisons. +\item[(8)] The \method{sort()} method takes optional arguments for +  controlling the comparisions.    \var{cmp} specifies a custom comparison function of two arguments       (list items) which should return a negative, zero or positive number @@ -1068,8 +1065,7 @@ Notes:    \versionchanged[Support for \var{key} and \var{reverse} was added]{2.4}  \item[(9)]  Starting with Python 2.3, the \method{sort()} method is -  guaranteed to be stable.  Starting with Python 2.4, the \method{sorted()} -  method is also guaranteed to be stable.  A sort is stable if it does not +  guaranteed to be stable.  A sort is stable if it guarantees not to    change the relative order of elements that compare equal --- this is    helpful for sorting in multiple passes (for example, sort by    department, then by salary grade). @@ -1079,9 +1075,6 @@ Notes:    of Python 2.3 makes the list appear empty for the duration, and raises    \exception{ValueError} if it can detect that the list has been    mutated during a sort. - -\item[(11)] \method{sorted()} is a class method that returns a new list. -  \versionadded{2.4}  \end{description}  \subsection{Set Types \label{types-set}} diff --git a/Doc/whatsnew/whatsnew24.tex b/Doc/whatsnew/whatsnew24.tex index 9e699a3dce..a881393105 100644 --- a/Doc/whatsnew/whatsnew24.tex +++ b/Doc/whatsnew/whatsnew24.tex @@ -177,9 +177,9 @@ they were input.  For example, you can sort a list of people by name,  and then sort the list by age, resulting in a list sorted by age where  people with the same age are in name-sorted order. -\item The list type gained a \method{sorted(iterable)} method that works -like the in-place \method{sort()} method but has been made suitable for -use in expressions.  The differences are: +\item There is a new builtin function \function{sorted(iterable)} that works +like the in-place \method{list.sort()} method but has been made suitable +for use in expressions.  The differences are:    \begin{itemize}    \item the input may be any iterable;    \item a newly formed copy is sorted, leaving the original intact; and @@ -188,17 +188,17 @@ use in expressions.  The differences are:  \begin{verbatim}  >>> L = [9,7,8,3,2,4,1,6,5] ->>> [10+i for i in list.sorted(L)]  # usable in a list comprehension +>>> [10+i for i in sorted(L)]       # usable in a list comprehension  [11, 12, 13, 14, 15, 16, 17, 18, 19]  >>> L = [9,7,8,3,2,4,1,6,5]         # original is left unchanged  [9,7,8,3,2,4,1,6,5]    ->>> list.sorted('Monte Python')     # any iterable may be an input +>>> sorted('Monte Python')          # any iterable may be an input  [' ', 'M', 'P', 'e', 'h', 'n', 'n', 'o', 'o', 't', 't', 'y']  >>> # List the contents of a dict sorted by key values  >>> colormap = dict(red=1, blue=2, green=3, black=4, yellow=5) ->>> for k, v in list.sorted(colormap.iteritems()): +>>> for k, v in sorted(colormap.iteritems()):  ...     print k, v  ...  black 4 @@ -301,14 +301,14 @@ counting, or identifying duplicate elements:  \begin{verbatim}  >>> word = 'abracadabra' ->>> word = list.sorted(word)   # Turn string into sorted list of letters ->>> word  +>>> letters = sorted(word)   # Turn string into sorted list of letters +>>> letters   ['a', 'a', 'a', 'a', 'a', 'b', 'b', 'c', 'd', 'r', 'r'] ->>> [k for k, g in groupby(word)]   # List the various group keys +>>> [k for k, g in groupby(word)]                     # List unique letters  ['a', 'b', 'c', 'd', 'r'] ->>> [(k, len(list(g))) for k, g in groupby(word)] # List key and group length +>>> [(k, len(list(g))) for k, g in groupby(word)]     # Count letter occurences  [('a', 5), ('b', 2), ('c', 1), ('d', 1), ('r', 2)] ->>> [k for k, g in groupby(word) if len(list(g)) > 1] # All groups of size >1 +>>> [k for k, g in groupby(word) if len(list(g)) > 1] # List duplicate letters  ['a', 'b', 'r']  \end{verbatim}  | 
