赞
踩
dic = {}
type (dic)
#output:<type 'dict'>
dic = {'a':1, 'b':2, 'c':3}
list = [('aaa', 1), ('bbb', 2), ('ccc', 3)]
dic = dict(list)
print(dic)
输出结果:
{'a': 1, 'b': 2, 'c': 3}
list = dict(a = 1, b = 2, c = 3)
print(list)
输出结果:
{'a': 1, 'b': 2, 'c': 3}
dic = dict(zip('abc', [1, 2, 3]))
print(dic)
输出结果:
{'a': 1, 'c': 3, 'b': 2}
dic = dict(zip(['a','b','c'], [1, 2, 3]))
print(dic)
输出结果:
{'a': 1, 'b': 2, 'c': 3}
dic = dict(zip(('a','b','c'), [1, 2, 3]))
print(dic)
输出结果:
{'a': 1, 'b': 2, 'c': 3}
dic = dict(zip(['a','b','c'], (1, 2, 3)))
print(dic)
输出结果:
{'a': 1, 'b': 2, 'c': 3}
dic = dict(zip(('a','b','c'), (1, 2, 3)))
print(dic)
输出结果:
{'a': 1, 'b': 2, 'c': 3}
dic = {i:2*i for i in range(3)}
print(dic)
输出结果:
{0: 0, 1: 2, 2: 4}
dic = dict.fromkeys(range(3), 'x')
print(dic)
输出结果:
{0: 'x', 1: 'x', 2: 'x'}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。