Why do I get an unhashable type 'list' error when converting a list to a set and back

∥☆過路亽.° 提交于 2019-12-02 11:43:33

total_words must contain sublists for this error to occur.

Consider:

>>> total_words = ['red', 'red', 'blue']
>>> list(set(total_words))
['blue', 'red']
>>> total_words = ['red', ['red', 'blue']] # contains a sublist
>>> list(set(total_words))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unhashable type: 'list'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!