summaryrefslogtreecommitdiff
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-04 08:25:44 +0000
committerRaymond Hettinger <python@rcn.com>2004-03-04 08:25:44 +0000
commitd31e0c6289652e5d997755b7bc93afc6f88070e0 (patch)
tree3e7ecbcc02d39da7543cb7cbc3c993953bbab41b /Doc
parentf8c850b7561852499f61ee44119ba0da8183cc47 (diff)
downloadcpython-d31e0c6289652e5d997755b7bc93afc6f88070e0.tar.gz
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.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/lib/libstdtypes.tex13
-rw-r--r--Doc/whatsnew/whatsnew24.tex4
2 files changed, 14 insertions, 3 deletions
diff --git a/Doc/lib/libstdtypes.tex b/Doc/lib/libstdtypes.tex
index 7c5cba0dc9..c39be284b1 100644
--- a/Doc/lib/libstdtypes.tex
+++ b/Doc/lib/libstdtypes.tex
@@ -1266,9 +1266,9 @@ arbitrary objects):
{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 @@ new dictionary. \var{value} defaults to \code{None}. \versionadded{2.3}
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}}
diff --git a/Doc/whatsnew/whatsnew24.tex b/Doc/whatsnew/whatsnew24.tex
index eb377bec68..24650fa5bc 100644
--- a/Doc/whatsnew/whatsnew24.tex
+++ b/Doc/whatsnew/whatsnew24.tex
@@ -134,6 +134,10 @@ language.
\begin{itemize}
+\item The \method{dict.update()} method now accepts the same
+argument forms as the \class{dict} constructor. This includes any
+mapping, any iterable of key/value pairs, and/or keyword arguments.
+
\item The string methods, \method{ljust()}, \method{rjust()}, and
\method{center()} now take an optional argument for specifying a
fill character other than a space.