fromkeys

fromkeys会返回新的字典与原字典没关系,直接用字典去访问fromkeys不会对字典产生影响的

dic = {}
a = dic.fromkeys("abc",[1,2,3])  #前面的会迭代添加,后面不会
print(a)
<<<<{'a': [1, 2, 3], 'b': [1, 2, 3], 'c': [1, 2, 3]}

 

posted @ 2019-08-05 19:53  tiwe  阅读(152)  评论(0编辑  收藏  举报