List changed; in Python, mutable containers are not hashed. set
, in turn, means elements that can be hashed. You can convert lists to tuples, which are immutable containers and thus hashed:
>>> myList = [[0, 1, 9], [0, 1, 9], [0, 1, 9], [8, 10, 16], [8, 10, 16], [8, 10, 16]] >>> list(set(tuple(i) for i in myList)) [(8, 10, 16), (0, 1, 9)]
Note that sets are not sorted, so you probably want to sort after creating the set:
>>> myList = [[0, 1, 9], [0, 1, 9], [0, 1, 9], [8, 10, 16], [8, 10, 16], [8, 10, 16]] >>> sorted(set(tuple(i) for i in myList)) [(0, 1, 9), (8, 10, 16)]