diff Doc/lib/libstdtypes.tex @ 31616:5b3898d9ba59 legacy-trunk

SF #904720: dict.update should take a 2-tuple sequence like dict.__init_ (Championed by Bob Ippolito.) The update() method for mappings now accepts all the same argument forms as the dict() constructor. This includes item lists and/or keyword arguments.
author Raymond Hettinger <python@rcn.com>
date Thu, 04 Mar 2004 08:25:44 +0000
parents c088584f5533
children 228d264c5fbb
line wrap: on
line diff
--- a/Doc/lib/libstdtypes.tex	Thu Mar 04 08:00:54 2004 +0000
+++ b/Doc/lib/libstdtypes.tex	Thu Mar 04 08:25:44 2004 +0000
@@ -1266,9 +1266,9 @@
           {a copy of \var{a}'s list of (\var{key}, \var{value}) pairs}
           {(3)}
   \lineiii{\var{a}.keys()}{a copy of \var{a}'s list of keys}{(3)}
-  \lineiii{\var{a}.update(\var{b})}
-          {\code{for \var{k} in \var{b}.keys(): \var{a}[\var{k}] = \var{b}[\var{k}]}}
-          {}
+  \lineiii{\var{a}.update(\optional{\var{b}})}
+          {updates (and overwrites) key/value pairs from \var{b}}
+          {(9)}
   \lineiii{\var{a}.fromkeys(\var{seq}\optional{, \var{value}})}
           {Creates a new dictionary with keys from \var{seq} and values set to \var{value}}
           {(7)}			   
@@ -1338,6 +1338,13 @@
 value is given and the key is not found.  \versionadded{2.3}
 \end{description}
 
+\item[(9)] \function{update()} accepts either another mapping object
+or an iterable of key/value pairs (as a tuple or other iterable of
+length two).  If keyword arguments are specified, the mapping is
+then is updated with those key/value pairs:
+\samp{d.update(red=1, blue=2)}.
+\versionchanged[Allowed the argument to be an iterable of key/value
+                pairs and allowed keyword arguments]{2.4}
 
 \subsection{File Objects
             \label{bltin-file-objects}}