dict

Description

Returns a dictionary object.

Syntax

dict ([**kwargs])

dict ([mapping, **kwargs])

dict ([iterable, **kwargs])

kwargs
Optional. Keyword arguments.
mapping
Optional. Another dictionary.
iterable
Optional. An iterable object in a form of key-value pair(s). keys should be immutable.

Return Value

dict

Time Complexity

#TODO

Remarks

If no positional argument is given, an empty dictionary is created. If a positional argument is given and it is a mapping object, a dictionary is created with the same key-value pairs as the mapping object. Otherwise, the positional argument must be an iterable object. Each item in the iterable must itself be an iterable with exactly two objects. The first object of each item becomes a key in the new dictionary, and the second object the corresponding value. If a key occurs more than once, the last value for that key becomes the corresponding value in the new dictionary.

If keyword arguments are given, the keyword arguments and their values are added to the dictionary created from the positional argument. If a key being added is already present, the value from the keyword argument replaces the value from the positional argument.

Example

>>> dict()
{}
>>> dict(a=1, b=2)
{'a': 1, 'b': 2}
>>> dict({'a': 1, 'b': 2}, c=3)
{'a': 1, 'b': 2, 'c': 3}
>>> dict([('a', 1), ['b', 2]], c=3)
{'a': 1, 'b': 2, 'c': 3}

See Also

#TODO