I want the unique list from the following list of list.
A = [[-1, 0, 1], [-1, -1, 2], [-1, 0, 1]]
output = [[-1,0,1], [-1,-1,2]]
I don't want to use any package. could you help me with that?
I want the unique list from the following list of list.
A = [[-1, 0, 1], [-1, -1, 2], [-1, 0, 1]]
output = [[-1,0,1], [-1,-1,2]]
I don't want to use any package. could you help me with that?
You can use set to get a unique list from number of lists
unique_data = [list(x) for x in set(tuple(x) for x in A)]
This will generate your expected output. :)
The other answer is correct but it doesn't maintain the original list order.
In case the order is important to you :
A = [['a', 0, 1], [-1, -1, 2], ['a', 0, 1]]
res = [list(i) for i in dict.fromkeys(map(tuple, A))]
print(res)
output :
[['a', 0, 1], [-1, -1, 2]]
Note : I've put 'a'
inside the sub lists in order to show you that in several runs you will get different result by using sets in other solution. Dictionaries maintain the insertion order now.