My list is like this: [['a','b'],['c','a'],['k','f'],['s','b'],['a','b']...]
I want to get a new list which has no duplicate elements from it. What is the fastest way to realize it ?
Asked
Active
Viewed 84 times
1

yanachen
- 3,401
- 8
- 32
- 64
-
By 'duplicate elements', are you referring to the inner lists (ex: `['a', 'b']`), or to the individual elements (ex: `'a'`)? – ATOMP Nov 09 '17 at 02:18
1 Answers
1
Using sets; first you need to cast the inner lists to non mutable types (tuples):
uniques = set(tuple(elt) for elt in ([['a','b'],['c','a'],['k','f'],['s','b'],['a','b']]))
output
{('a', 'b'), ('c', 'a'), ('k', 'f'), ('s', 'b')}
Please note that sets will not preserve the order of the elements.

Reblochon Masque
- 35,405
- 10
- 55
- 80