1.使用itertools模块
import itertoolsthe_key = ['ab','22',33]the_vale = ['aaaa',"dddddddd",'22222222222']d = dict(itertools.izip(the_key,the_vale))print d2.加参数
3.使用内置的zip函数
zip([iterable,…])返回一个列表武汉网站优化
1.使用itertools模块
import itertoolsthe_key = ['ab','22',33]the_vale = ['aaaa',"dddddddd",'22222222222']d = dict(itertools.izip(the_key,the_vale))print d2.加参数
3.使用内置的zip函数
zip([iterable,…])返回一个列表
结果:
type 'list'{33: '22222222222', 'ab': 'aaaa', '22': 'dddddddd'}4.dict的fromkeys函数
创建的每个键有相同的value
结果:{33: 0, ‘ab’: 0, ’22’: 0}
import stringcount_by_letter = dict.fromkeys(string.ascii_lowercase,0)print count_by_letter结果:
{'a': 0, 'c': 0, 'b': 0, 'e': 0, 'd': 0, 'g': 0, 'f': 0, 'i': 0, 'h': 0, 'k': 0, 'j': 0, 'm': 0, 'l': 0, 'o': 0, 'n': 0, 'q': 0, 'p': 0, 's': 0, 'r': 0, 'u': 0, 't': 0, 'w': 0, 'v': 0, 'y': 0, 'x': 0, 'z': 0}希望本文所述对大家Python程序设计的学习有所帮助。
武汉网站优化 the_key = ['ab','22',33]the_vale = ['aaaa',"dddddddd",'22222222222']dict2 = dict(zip(the_key,the_vale))print type(zip(the_key,the_vale))print dict2结果:
type 'list'{33: '22222222222', 'ab': 'aaaa', '22': 'dddddddd'}4.dict的fromkeys函数
创建的每个键有相同的value
结果:{33: 0, ‘ab’: 0, ’22’: 0}
import stringcount_by_letter = dict.fromkeys(string.ascii_lowercase,0)print count_by_letter结果: