summaryrefslogtreecommitdiffstats
path: root/Doc/whatsnew
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2003-12-16 20:59:37 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2003-12-16 20:59:37 (GMT)
commit4612bc587b002841644d854cc3fd441e0ef71855 (patch)
tree1092caefefb20aa189188c693614412e1efaa764 /Doc/whatsnew
parent81ad32e43591bbc93af14da030b0946a896270f4 (diff)
downloadcpython-4612bc587b002841644d854cc3fd441e0ef71855.zip
cpython-4612bc587b002841644d854cc3fd441e0ef71855.tar.gz
cpython-4612bc587b002841644d854cc3fd441e0ef71855.tar.bz2
Make example more readable
Diffstat (limited to 'Doc/whatsnew')
-rw-r--r--Doc/whatsnew/whatsnew24.tex9
1 files changed, 6 insertions, 3 deletions
diff --git a/Doc/whatsnew/whatsnew24.tex b/Doc/whatsnew/whatsnew24.tex
index e0e2c9c..9e699a3 100644
--- a/Doc/whatsnew/whatsnew24.tex
+++ b/Doc/whatsnew/whatsnew24.tex
@@ -301,11 +301,14 @@ counting, or identifying duplicate elements:
\begin{verbatim}
>>> word = 'abracadabra'
->>> [k for k, g in groupby(list.sorted(word))]
+>>> 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(list.sorted(word))]
+>>> [(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(list.sorted(word)) if len(list(g)) > 1]
+>>> [k for k, g in groupby(word) if len(list(g)) > 1] # All groups of size >1
['a', 'b', 'r']
\end{verbatim}