List unhashable, but tuple hashable?

前端 未结 6 871
渐次进展
渐次进展 2020-12-08 10:15

In How to hash lists? I was told that I should convert to a tuple first, e.g. [1,2,3,4,5] to (1,2,3,4,5).

So the first cannot be hashed, bu

6条回答
  •  臣服心动
    2020-12-08 10:26

    Not every tuple is hashable.For example tuple contains list as an element.

    x = (1,[2,3])
    print(type(x))
    print(hash(x))
    

提交回复
热议问题