python 快速创建字典 fromkes()

2020-12-13 16:43

阅读:309

标签:one   from   style   val   lis   rom   创建   pre   span   

作用:快速创建字典

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

标签:one   from   style   val   lis   rom   创建   pre   span   

原文地址:https://www.cnblogs.com/wt7018/p/11621504.html


评论


亲,登录后才可以留言!