Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我会得到一个不易损坏的类型';列表';将列表转换为集合并返回时出错_Python_List_Set_Duplicates_Typeerror - Fatal编程技术网

Python 为什么我会得到一个不易损坏的类型';列表';将列表转换为集合并返回时出错

Python 为什么我会得到一个不易损坏的类型';列表';将列表转换为集合并返回时出错,python,list,set,duplicates,typeerror,Python,List,Set,Duplicates,Typeerror,和这里的许多其他问题一样,我试图从列表中删除重复项。但是,当我执行其他答案声称有效的代码时,我得到以下错误: TypeError: unhashable type: 'list' 在以下代码行中: total_unique_words = list(set(total_words)) 有人知道这个问题的可能解决办法吗?这是因为在大多数情况下,原始结构不是列表吗 谢谢 若要发生此错误,则必须包含子列表 考虑: >>> total_words = ['red', 'red',

和这里的许多其他问题一样,我试图从列表中删除重复项。但是,当我执行其他答案声称有效的代码时,我得到以下错误:

TypeError: unhashable type: 'list'
在以下代码行中:

total_unique_words = list(set(total_words))
有人知道这个问题的可能解决办法吗?这是因为在大多数情况下,原始结构不是列表吗


谢谢

若要发生此错误,则必须包含子列表

考虑:

>>> 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'
>>总单词数=['red'、'red'、'blue']
>>>列表(集合(总字数))
[‘蓝色’、‘红色’]
>>>总单词数=['red'、['red'、['blue']]#包含一个子列表
>>>列表(集合(总字数))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:不可损坏的类型:“列表”

total_words
必须包含发生此错误的子列表

考虑:

>>> 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'
>>总单词数=['red'、'red'、'blue']
>>>列表(集合(总字数))
[‘蓝色’、‘红色’]
>>>总单词数=['red'、['red'、['blue']]#包含一个子列表
>>>列表(集合(总字数))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:不可损坏的类型:“列表”

total_words
必须包含发生此错误的子列表

考虑:

>>> 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'
>>总单词数=['red'、'red'、'blue']
>>>列表(集合(总字数))
[‘蓝色’、‘红色’]
>>>总单词数=['red'、['red'、['blue']]#包含一个子列表
>>>列表(集合(总字数))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:不可损坏的类型:“列表”

total_words
必须包含发生此错误的子列表

考虑:

>>> 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'
>>总单词数=['red'、'red'、'blue']
>>>列表(集合(总字数))
[‘蓝色’、‘红色’]
>>>总单词数=['red'、['red'、['blue']]#包含一个子列表
>>>列表(集合(总字数))
回溯(最近一次呼叫最后一次):
文件“”,第1行,在
TypeError:不可损坏的类型:“列表”

可能更可能
[['red'、'red'、'blue']]
-整个列表是一个子列表。@MarkRansom:这是一个合理的可能性。我会让你的评论来澄清。是的,就是这样,现在看起来很明显。谢谢可能更可能是
[['red'、'red'、'blue']]
-整个列表是一个子列表。@MarkRansom:这是一个很好的可能性。我会让你的评论来澄清。是的,就是这样,现在看起来很明显。谢谢可能更可能是
[['red'、'red'、'blue']]
-整个列表是一个子列表。@MarkRansom:这是一个很好的可能性。我会让你的评论来澄清。是的,就是这样,现在看起来很明显。谢谢可能更可能是
[['red'、'red'、'blue']]
-整个列表是一个子列表。@MarkRansom:这是一个很好的可能性。我会让你的评论来澄清。是的,就是这样,现在看起来很明显。谢谢显示用于创建
总单词数的实际代码。我怀疑你认为这应该是一个字符串列表,而实际上它可能是一个列表列表。显示你用来创建
total\u words
的实际代码。我怀疑你认为这应该是一个字符串列表,而实际上它可能是一个列表列表。显示你用来创建
total\u words
的实际代码。我怀疑你认为这应该是一个字符串列表,而实际上它可能是一个列表列表。显示你用来创建
total\u words
的实际代码。我怀疑你认为这应该是一个字符串列表,而实际上它可能是一个列表列表。