python中dict的value为list时更新

python中dict的value为list时更新,第1张

python中dict的value为list时更新
for i in list1:
    dict.update({i:[1, 0, 0, 0, 0, 0, 0, 0, 0]})
    print(i,dict[i])

结果:

 [1, 0, 0, 0, 0, 0, 0, 0, 0]
 [1, 0, 0, 0, 0, 0, 0, 0, 0]
 [1, 0, 0, 0, 0, 0, 0, 0, 0]
 [1, 0, 0, 0, 0, 0, 0, 0, 0]
 [1, 0, 0, 0, 0, 0, 0, 0, 0]

update里面不能用=,得用{}

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5580245.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-14

发表评论

登录后才能评论

评论列表(0条)

    保存