Python removes equal lists
6 answers
A variation on @ DYZ's answer that works on lists containing identical elements regardless of order:
[x for x,_ in itertools.groupby(map(set, a))]
For example:
>>> a = [['a'],['a'],['b'],['b'],['c', 'a'],['a', 'c']]
>>> [list(x) for x,_ in itertools.groupby(map(set, a))]
[['a'], ['b'], ['a', 'c']]
If ['c', 'a']
both are ['a', 'c']
not considered equal (see comments below from @DYZ), you can do something like this with set()
:
map(list, set(map(tuple, a)))
0
source to share