[Python-checkins] python/dist/src/Doc/tut tut.tex,1.156.4.1.2.3,1.156.4.1.2.4

rhettinger@users.sourceforge.net rhettinger@users.sourceforge.net
Tue, 25 Jun 2002 08:02:36 -0700


Update of /cvsroot/python/python/dist/src/Doc/tut
In directory usw-pr-cvs1:/tmp/cvs-serv28601

Modified Files:
      Tag: release22-maint
	tut.tex 
Log Message:
Close bug 480337:  Dict used before dicts explained.  Added explanation
and examples of the dict() constructor.


Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.156.4.1.2.3
retrieving revision 1.156.4.1.2.4
diff -C2 -d -r1.156.4.1.2.3 -r1.156.4.1.2.4
*** tut.tex	11 Jun 2002 02:57:32 -0000	1.156.4.1.2.3
--- tut.tex	25 Jun 2002 15:02:31 -0000	1.156.4.1.2.4
***************
*** 2024,2027 ****
--- 2024,2039 ----
  \end{verbatim}
  
+ The \function{dict()} contructor builds dictionaries directly from
+ lists of key-value pairs stored as tuples.  When the pairs form a
+ pattern, list comprehensions can compactly specify the key-value list.
+ 
+ \begin{verbatim}
+ >>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
+ {'sape': 4139, 'jack': 4098, 'guido': 4127}
+ >>> dict([(x, x**2) for x in vec])     # use a list comprehension
+ {2: 4, 4: 16, 6: 36}
+ \end{verbatim}
+ 
+ 
  \section{More on Conditions \label{conditions}}