python遇到TypeError: unhashable type: ‘list’
今天在写这个泰坦尼克号的时候,出现了这个bug。

后来检查后,才发现Embarked这一列被我改成list类型了,自然不能够hash。因此对原始数据,重新跑一遍后,结果正确。
Examples of hashable objects:
1 | int, float, decimal, complex, bool, string, tuple, range, frozenset, bytes |
Examples of Unhashable objects:
1 | list, dict, set, bytearray, user-defined classes |
1 2 3 4 | my_dict = {'name': 'John', tuple([1,2,3]):'values'} print(my_dict) output: {'name': 'John', (1, 2, 3): 'values'} |
另外:
- Tuple and List
尽管
2. hashing
Now you’re ready to solve this error like a professional coder!