python中生成字典
1、
>>> a = {"a":111,"b":222,"c":333,"d":444}
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> len(a)
4
>>> type(a)
<class 'dict'>
2、
>>> a = dict((("a",111),("b",222),("c",333),("d",444)))
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> len(a)
4
>>> type(a)
<class 'dict'>
3、
>>> a = dict(a = 111, b = 222, c = 333, d = 444)
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> len(a)
4
>>> type(a)
<class 'dict'>
4、
>>> a = {}
>>> a["a"] = 111
>>> a["b"] = 222
>>> a
{'a': 111, 'b': 222}
>>> len(a)
2
>>> type(a)
<class 'dict'>
5、
>>> a = dict(zip(("a","b","c","d"),(111,222,333,444)))
>>> a
{'a': 111, 'b': 222, 'c': 333, 'd': 444}
>>> type(a)
<class 'dict'>
>>> len(a)
4
6、
>>> a = {}
>>> a = a.fromkeys(("a","b","c","d"),"xxxx")
>>> a
{'a': 'xxxx', 'b': 'xxxx', 'c': 'xxxx', 'd': 'xxxx'}
>>> b = {}
>>> b = a.fromkeys(range(20),"xxxx")
>>> b
{0: 'xxxx', 1: 'xxxx', 2: 'xxxx', 3: 'xxxx', 4: 'xxxx', 5: 'xxxx', 6: 'xxxx', 7: 'xxxx', 8: 'xxxx', 9: 'xxxx', 10: 'xxxx', 11: 'xxxx', 12: 'xxxx', 13: 'xxxx', 14: 'xxxx', 15: 'xxxx', 16: 'xxxx', 17: 'xxxx', 18: 'xxxx', 19: 'xxxx'}