为什么dict对象在python中是不可靠的? [英] why dict objects are unhashable in python?

查看:224
本文介绍了为什么dict对象在python中是不可靠的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的意思是为什么我们不能把dict的关键字作为dict?



这意味着我们不能把具有密钥的字典作为另一个字典...

解决方案

简短答案:因为它们是可变容器



如果一个dict被散列,它的哈希会改变,因为你改变了它的内容。


I mean why cant we put key of dict as dict?

that means we can't have dictionary having key as another dictionary...

解决方案

Short answer: because they are mutable containers.

If a dict was hashed, its hash would change as you changed its contents.

这篇关于为什么dict对象在python中是不可靠的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆