[Python-checkins] python/dist/src/Doc/whatsnew whatsnew24.tex, 1.17, 1.18

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Fri Dec 12 08:13:49 EST 2003


Update of /cvsroot/python/python/dist/src/Doc/whatsnew
In directory sc8-pr-cvs1:/tmp/cvs-serv9803
Modified Files:
	whatsnew24.tex 
Log Message:
Expand the groupby() example to:
* show that it is typically used with sorted data,
* highlight commonalities with SQL's groupby and Unix's uniq,
* demonstrate valid uses for the default identity function,
* add some excitement by suggesting the range of possibilities.
Index: whatsnew24.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/whatsnew/whatsnew24.tex,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** whatsnew24.tex	6 Dec 2003 23:19:23 -0000	1.17
--- whatsnew24.tex	12 Dec 2003 13:13:47 -0000	1.18
***************
*** 295,298 ****
--- 295,313 ----
 \end{verbatim}
 
+ Like its SQL counterpart, \function{groupby()} is typically used with
+ sorted input. The logic for \function{groupby()} is similar to the
+ \UNIX{} \code{uniq} filter which makes it handy for eliminating,
+ counting, or identifying duplicate elements:
+ 
+ \begin{verbatim}
+ >>> word = 'abracadabra'
+ >>> [k for k, g in groupby(list.sorted(word))]
+ ['a', 'b', 'c', 'd', 'r']
+ >>> [(k, len(list(g))) for k, g in groupby(list.sorted(word))]
+ [('a', 5), ('b', 2), ('c', 1), ('d', 1), ('r', 2)]
+ >>> [k for k, g in groupby(list.sorted(word)) if len(list(g)) > 1]
+ ['a', 'b', 'r']
+ \end{verbatim}
+ 
 \item A new \function{getsid()} function was added to the
 \module{posix} module that underlies the \module{os} module.


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /