If you want a solution that works for all lists
, not just the one you provided, you can use set
and frozenset
to get a set
of unique frozenset
s and convert back to lists.
l = [[1, -2, 3], [1, -2, -4], [1, -2, 1], [3, -2, 1], [-4, 1, 2]]
unique = set(map(frozenset, l))
will give you a set of frozen sets. If you want to convert the elements back into lists you can do
unique_l = list(map(list, set(map(frozenset, l))))
per @wim's points if the sub-lists can contain duplicates
kept = {}
for e in l:
key = tuple(sorted(e))
if key not in kept:
kept[key] = e
unique_l = list(kept.values())
and if order of the original list and the sublists matter as well you wanting to be keep the first occurrence of the unique sublist.