>>># 1. 用键值表的方式创建字典>>> a =dict(one=1, two=2, three=3)>>> a
{'three':3,'two':2,'one':1}>>># 2. 最常用的文字表达式>>> b ={"one":1,"two":2,"three":3}>>> b
{'three':3,'one':1,'two':2}>>># 3. 动态分配键值>>> c ={}>>> c["one"]=1>>> c["two"]=2>>> c["three"]=3>>> c
{'three':3,'one':1,'two':2}>>># 4. 利用zip方法>>> d =dict(zip(['one','two','three'],[1,2,3]))>>> d
{'three':3,'one':1,'two':2}>>># 5. 元组键值表>>> e =dict([("one",1),("two",2),("three",3)])>>> e
{'three':3,'one':1,'two':2}>>># 6. 字典推导式>>>dict=[("one",1),("two",2),("three",3)]>>> f ={key: value for key,value indict}>>> f
{'three':3,'one':1,'two':2}>>># 7. d.fromkeys(it, [initial])>>># 将迭代器 it 里的元素设置为映射里的键,如果有 initial参数,就把它作为这些键对应的值(默认是 None )>>> d.fromkeys(["one","two","three"],[1,2,3]){'three':[1,2,3],'one':[1,2,3],'two':[1,2,3]}