@@ -2114,33 +2114,41 @@ Dictionaries can be created by placing a comma-separated list of ``key: value``
21142114pairs within braces, for example: ``{'jack': 4098, 'sjoerd': 4127} `` or ``{4098:
21152115'jack', 4127: 'sjoerd'} ``, or by the :class: `dict ` constructor.
21162116
2117- .. class :: dict([arg])
2118-
2119- Return a new dictionary initialized from an optional positional argument or
2120- from a set of keyword arguments. If no arguments are given, return a new
2121- empty dictionary. If the positional argument *arg * is a mapping object,
2122- return a dictionary mapping the same keys to the same values as does the
2123- mapping object. Otherwise the positional argument must be a sequence, a
2124- container that supports iteration, or an iterator object. The elements of
2125- the argument must each also be of one of those kinds, and each must in turn
2126- contain exactly two objects. The first is used as a key in the new
2127- dictionary, and the second as the key's value. If a given key is seen more
2128- than once, the last value associated with it is retained in the new
2117+ .. class :: dict(**kwarg)
2118+ dict(mapping, **kwarg)
2119+ dict(iterable, **kwarg)
2120+
2121+ Return a new dictionary initialized from an optional positional argument
2122+ and a possibly empty set of keyword arguments.
2123+
2124+ If no positional argument is given, an empty dictionary is created.
2125+ If a positional argument is given and it is a mapping object, a dictionary
2126+ is created with the same key-value pairs as the mapping object. Otherwise,
2127+ the positional argument must be an :term: `iterator ` object. Each item in
2128+ the iterable must itself be an iterator with exactly two objects. The
2129+ first object of each item becomes a key in the new dictionary, and the
2130+ second object the corresponding value. If a key occurs more than once, the
2131+ last value for that key becomes the corresponding value in the new
21292132 dictionary.
21302133
2131- If keyword arguments are given, the keywords themselves with their associated
2132- values are added as items to the dictionary. If a key is specified both in
2133- the positional argument and as a keyword argument, the value associated with
2134- the keyword is retained in the dictionary. For example, these all return a
2135- dictionary equal to ``{"one": 1, "two": 2} ``:
2134+ If keyword arguments are given, the keyword arguments and their values are
2135+ added to the dictionary created from the positional argument. If a key
2136+ being added is already present, the value from the keyword argument
2137+ replaces the value from the positional argument.
21362138
2137- * ``dict(one=1, two=2) ``
2138- * ``dict({'one': 1, 'two': 2}) ``
2139- * ``dict(zip(('one', 'two'), (1, 2))) ``
2140- * ``dict([['two', 2], ['one', 1]]) ``
2139+ To illustrate, the following examples all return a dictionary equal to
2140+ ``{"one": 1, "two": 2} ``::
21412141
2142- The first example only works for keys that are valid Python identifiers; the
2143- others work with any valid keys.
2142+ >>> a = dict(one=1, two=2)
2143+ >>> b = dict({'one': 1, 'two': 2})
2144+ >>> c = dict(zip(('one', 'two'), (1, 2)))
2145+ >>> d = dict([['two', 2], ['one', 1]])
2146+ >>> e = {"one": 1, "two": 2}
2147+ >>> a == b == c == d == e
2148+ True
2149+
2150+ Providing keyword arguments as in the first example only works for keys that
2151+ are valid Python identifiers. Otherwise, any valid keys can be used.
21442152
21452153
21462154 These are the operations that dictionaries support (and therefore, custom
0 commit comments