When run the following code in a scratch file, everything works:
x = [1,1,1]
print(set(x))
> {1}
And yet when I run the following code
class MyClass(object):
def __init__(self):
self.mylist = []
def train(self,vector):
self.mylist.append(vector)
self.mylist = list(set(self.mylist))
I get the error, TypeError: unhashable type: 'list'.
What's the problem here?
vector?vectoris a list, it can't go inside a set. You'd probably want to use atuple(immutable list) instead.vectorto a tuple or to use.extendrather than.append