Skip to content Skip to sidebar Skip to footer

Why Do I Get An Unhashable Type 'list' Error When Converting A List To A Set And Back

Like many other questions on here, I'm attempting to remove duplicates from a list. However, when I execute code that other answers claim work I get the following error: TypeError

Solution 1:

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'

Post a Comment for "Why Do I Get An Unhashable Type 'list' Error When Converting A List To A Set And Back"