I have a 2-d array
xx=[[a,1],[b,2],[c,3]]
Now I’m trying to remove duplicate entries from it. For simple 1-D array, simple code like
xx=list(set(xx))
would work. But trying set on 2-d elements gives an error
temp = set(xx)
TypeError: unhashable type: 'list'
One workaround would be to serialize xx elements, and then do a list(set()) on new array and then unserialize all the elements back again.
Is there any solution in python?
Convert elements to tuple and then use
set.Tuples, unlike lists, can be hashed. Hence. And once you are done, convert the elements back to list. Putting everything together: