python 快速创建字典 fromkes()

Posted wt7018

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 快速创建字典 fromkes()相关的知识,希望对你有一定的参考价值。

作用:快速创建字典

特点:共用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

 

以上是关于python 快速创建字典 fromkes()的主要内容,如果未能解决你的问题,请参考以下文章