python 基础
2018-10-30 本文已影响0人
RICKYMAN
1030
>>> b
[1, 3, [1, 2], [1, 2]]
>>> list(b)
[1, 3, [1, 2], [1, 2]]
>>> set(b)
Traceback (most recent call last):
File "<pyshell#38>", line 1, in <module>
set(b)
TypeError: unhashable type: 'list'
原因:set 用hash计算的,因此元素不可变,但是列表是可变的