[Python-checkins]
python/dist/src/Doc/whatsnew whatsnew24.tex, 1.18, 1.19
akuchling at users.sourceforge.net
akuchling at users.sourceforge.net
Tue Dec 16 15:59:39 EST 2003
Update of /cvsroot/python/python/dist/src/Doc/whatsnew
In directory sc8-pr-cvs1:/tmp/cvs-serv30782
Modified Files:
whatsnew24.tex
Log Message:
Make example more readable
Index: whatsnew24.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/whatsnew/whatsnew24.tex,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** whatsnew24.tex 12 Dec 2003 13:13:47 -0000 1.18
--- whatsnew24.tex 16 Dec 2003 20:59:37 -0000 1.19
***************
*** 302,310 ****
\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}
--- 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}
More information about the Python-checkins
mailing list