[Python-checkins] python/dist/src/Doc/whatsnew whatsnew24.tex, 1.44, 1.45

rhettinger at users.sourceforge.net rhettinger at users.sourceforge.net
Wed May 19 15:45:21 EDT 2004


Update of /cvsroot/python/python/dist/src/Doc/whatsnew
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18118/Doc/whatsnew
Modified Files:
	whatsnew24.tex 
Log Message:
Add more docs for generator expressions.
* Put in a brief, example driven tutorial entry.
* Use better examples in whatsnew24.tex.
Index: whatsnew24.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/whatsnew/whatsnew24.tex,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** whatsnew24.tex	19 May 2004 08:20:04 -0000	1.44
--- whatsnew24.tex	19 May 2004 19:45:19 -0000	1.45
***************
*** 126,130 ****
 \function{dict()}. These functions consume their data all at once
 and would not benefit from having a full list instead of a generator
! an input:
 
 \begin{verbatim}
--- 126,130 ----
 \function{dict()}. These functions consume their data all at once
 and would not benefit from having a full list instead of a generator
! as an input:
 
 \begin{verbatim}
***************
*** 132,148 ****
 285
 
! >>> sorted(set(i*i for i in xrange(-10, 11)))
! [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
! 
! >>> words = "Adam apple baker Bill Nancy NASA nut".split()
! >>> dict((word.lower(), word) for word in words)
! {'apple': 'apple', 'baker': 'baker', 'bill': 'Bill', 'nasa': 'NASA',
! 'adam': 'Adam', 'nancy': 'Nancy', 'nut': 'nut'}
 
 >>> xvec = [10, 20, 30]
 >>> yvec = [7, 5, 3]
! >>> sum(x*y for x,y in itertools.izip(xvec, yvec)) # dot product
 260
 
 \end{verbatim} 
 
--- 132,151 ----
 285
 
! >>> sorted(set(i*i for i in xrange(-20, 20) if i%2==1)) # odd squares
! [1, 9, 25, 49, 81, 121, 169, 225, 289, 361]
 
+ >>> from itertools import izip
 >>> xvec = [10, 20, 30]
 >>> yvec = [7, 5, 3]
! >>> sum(x*y for x,y in izip(xvec, yvec)) # dot product
 260
 
+ >>> from math import pi, sin
+ >>> sine_table = dict((x, sin(x*pi/180)) for x in xrange(0, 91))
+ 
+ >>> unique_words = set(word for line in page for word in line.split())
+ 
+ >>> valedictorian = max((student.gpa, student.name) for student in graduates)
+ 
 \end{verbatim} 
 


More information about the Python-checkins mailing list

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