1、问题根源:
text = {"a":{"aa":1,"b":2},"b":2,"c":3,"d":4,"e":5}
list_dict = [{v:text[v]} for v in text]
set(list_dict)
输出:
TypeError Traceback (most recent call last)
<ipython-input-61-1aa0066cf4cc> in <module>()
1 text = {"a":{"aa":1,"b":2},"b":2,"c":3,"d":4,"e":5}
2 list_dict = [{v:text[v]} for v in text]
----> 3 set(list_dict)
TypeError: unhashable type: 'dict'
因为集合的元素类型只能是不可变数据类型,如整数,浮点数,字符串,元组等(列表,字典,集合类型本身都是可变数据类型,不能做集合的元素出现)
————————————————
版权声明:本文为CSDN博主「Takoony」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/ningyanggege/article/details/102514271