[Python-checkins] python/dist/src/Doc/tut tut.tex,1.272,1.273
rhettinger@users.sourceforge.net
rhettinger at users.sourceforge.net
Tue Jun 28 01:36:50 CEST 2005
Update of /cvsroot/python/python/dist/src/Doc/tut
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30414
Modified Files:
tut.tex
Log Message:
* Show the keyword argument form of dict().
* Note that dict works with the "in" keyword.
Index: tut.tex
===================================================================
RCS file: /cvsroot/python/python/dist/src/Doc/tut/tut.tex,v
retrieving revision 1.272
retrieving revision 1.273
diff -u -d -r1.272 -r1.273
--- tut.tex 17 Jun 2005 10:25:33 -0000 1.272
+++ tut.tex 27 Jun 2005 23:36:47 -0000 1.273
@@ -2146,8 +2146,8 @@
The \method{keys()} method of a dictionary object returns a list of all
the keys used in the dictionary, in arbitrary order (if you want it
sorted, just apply the \method{sort()} method to the list of keys). To
-check whether a single key is in the dictionary, use the
-\method{has_key()} method of the dictionary.
+check whether a single key is in the dictionary, either use the dictionary's
+\method{has_key()} method or the \keyword{in} keyword.
Here is a small example using a dictionary:
@@ -2166,6 +2166,8 @@
['guido', 'irv', 'jack']
>>> tel.has_key('guido')
True
+>>> 'guido' in tel
+True
\end{verbatim}
The \function{dict()} constructor builds dictionaries directly from
@@ -2183,6 +2185,14 @@
which are even better suited for the task of supplying key-values pairs to
the \function{dict()} constructor.
+When the keys are simple strings, it is sometimes easier to specify
+pairs using keyword arguments:
+
+\begin{verbatim}
+>>> dict(sape=4139, guido=4127, jack=4098)
+{'sape': 4139, 'jack': 4098, 'guido': 4127}
+\end{verbatim}
+
\section{Looping Techniques \label{loopidioms}}
More information about the Python-checkins
mailing list