From: Andrew M. Kuchling Date: Tue, 16 Dec 2003 20:59:37 +0000 (+0000) Subject: Make example more readable X-Git-Tag: v2.4a1~1083 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4612bc587b002841644d854cc3fd441e0ef71855;p=thirdparty%2FPython%2Fcpython.git Make example more readable --- diff --git a/Doc/whatsnew/whatsnew24.tex b/Doc/whatsnew/whatsnew24.tex index e0e2c9cc543b..9e699a3dcee5 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}