[Python-checkins] python/dist/src/Doc/whatsnew whatsnew24.tex, 1.19, 1.20

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed Dec 17 15:43:34 EST 2003


Update of /cvsroot/python/python/dist/src/Doc/whatsnew
In directory sc8-pr-cvs1:/tmp/cvs-serv9388/Doc/whatsnew

Modified Files:
	whatsnew24.tex 
Log Message:
Guido grants a Christmas wish:  
  sorted() becomes a regular function instead of a classmethod.



Index: whatsnew24.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/whatsnew/whatsnew24.tex,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** whatsnew24.tex	16 Dec 2003 20:59:37 -0000	1.19
--- whatsnew24.tex	17 Dec 2003 20:43:32 -0000	1.20
***************
*** 178,184 ****
  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:
    \begin{itemize}
    \item the input may be any iterable;
--- 178,184 ----
  people with the same age are in name-sorted order.
  
! \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;
***************
*** 189,203 ****
  \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
  [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
  [' ', '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()):
  ...     print k, v
  ...
--- 189,203 ----
  \begin{verbatim}
  >>> L = [9,7,8,3,2,4,1,6,5]
! >>> [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]   
  
! >>> 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 sorted(colormap.iteritems()):
  ...     print k, v
  ...
***************
*** 302,313 ****
  \begin{verbatim}
  >>> word = 'abracadabra'
! >>> word = list.sorted(word)   # Turn string into sorted list of letters
! >>> word 
  ['a', 'a', 'a', 'a', 'a', 'b', 'b', 'c', 'd', 'r', 'r']
! >>> [k for k, g in groupby(word)]   # List the various group keys
  ['a', 'b', 'c', 'd', 'r']
! >>> [(k, len(list(g))) for k, g in groupby(word)] # List key and group length
  [('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
  ['a', 'b', 'r']
  \end{verbatim}
--- 302,313 ----
  \begin{verbatim}
  >>> word = 'abracadabra'
! >>> 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 unique letters
  ['a', 'b', 'c', 'd', 'r']
! >>> [(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] # List duplicate letters
  ['a', 'b', 'r']
  \end{verbatim}





More information about the Python-checkins mailing list