summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2004-03-04 08:25:44 (GMT)
committerRaymond Hettinger <python@rcn.com>2004-03-04 08:25:44 (GMT)
commit31017aed36a5c5b0e4b16ca58bea09c9ce360134 (patch)
tree766d70bb4fbb6878a71c81fc3874515cfcbc8aa8 /Doc
parent6c79a518e70ea8e45e3287573d99c648ae3cb21b (diff)
downloadcpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.zip
cpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.tar.gz
cpython-31017aed36a5c5b0e4b16ca58bea09c9ce360134.tar.bz2
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 7c5cba0..c39be28 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 eb377be..24650fa 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.