Mapping Type Related Functions with dict() : Convert to Dictionary « Dictionary « Python Tutorial






print dict(zip(('x', 'y'), (1, 2)))
print dict([['x', 1], ['y', 2]])
print dict([('xy'[i-1], i) for i in range(1,3)])
print dict(x=1, y=2)
dict1 = dict(x=1, y=2)
print dict1
dict2 = dict(**dict1)
print dict2








8.5.Convert to Dictionary
8.5.1.use the dict function to construct dictionaries from (key, value) pairs
8.5.2.dict can be used with keyword arguments
8.5.3.dictionaries may be created using the factory function dict().
8.5.4.Mapping Type Related Functions with dict()