当前位置 : 主页 > 编程语言 > python >

python 快速创建字典 fromkes()

来源:互联网 收集:自由互联 发布时间:2021-06-25
作用:快速创建字典 特点:共用value seq = [ ‘ google ‘ , ‘ ie ‘ , ‘ firefox ‘ ] # seq为可迭代对象(str, list, tuple, dict, set) dic = dict.fromkeys(seq) print (dic) # {‘google‘: None, ‘ie‘: None, ‘

作用:快速创建字典

特点:共用value

seq = [google, ie, firefox]
# seq为可迭代对象(str, list, tuple, dict, set)
dic = dict.fromkeys(seq)
print(dic)      # {‘google‘: None, ‘ie‘: None, ‘firefox‘: None}

dic2 = dict.fromkeys(seq, 10)
print(dic2)     # {‘google‘: 10, ‘ie‘: 10, ‘firefox‘: 10}
网友评论