Reputation: 13
liste0 = []
liste1 = []
s1 = input("kişileri gir")
s2 = input("kişileri gene gir")
s1 = s1.split(",")
s2 = s2.split(",")
liste0.append(s1)
liste1.append(s2)
print(set(liste0) ^ set(liste1))
#error is: TypeError: unhashable type: 'list'
Upvotes: 0
Views: 33
Reputation: 12395
Do you mean to use extend
instead of append
?
liste0.extend(s1)
liste1.extend(s2)
When you use append
, you have a nested list. For example, if you enter 1,2,3
at your first prompt, you get list0 = [['1', '2', '3']]
, because it appended the split input as a list as a single element to the empty list.
But you cannot have lists inside of sets, for example:
print(set([0, 1, 2]))
# {0, 1, 2}
print(set([0, [1, 2]]))
# TypeError: unhashable type: 'list'
From the set()
docs:
Return a new set or frozenset object whose elements are taken from iterable. The elements of a set must be hashable.
From the hashable
docs:
Most of Python’s immutable built-in objects are hashable; mutable containers (such as lists or dictionaries) are not; immutable containers (such as tuples and frozensets) are only hashable if their elements are hashable.
Upvotes: 1