No Python, no built-in multiset; the closest equivalent in standard collections.Counter modules, which is a dictionary type. A counter may be appropriate for your needs, but it is hard to say without additional context.
Note that sets do not preserve the order of addition. If you need to keep the initial order of the lists, you can do what you want:
data = [[1, 2], [2, 1], [3, 2, 2], [2], [2, 1, 3], [2, 2, 3]] a = set() outlist = [] for s in data: t = tuple(sorted(s)) if t not in a: a.add(t) outlist.append(list(t)) print(outlist)
Output
[[1, 2], [2, 2, 3], [2], [1, 2, 3]]
If the number of input lists is rather small, you do not need a set (and transformations of the list β tuples), just check outlist membership. However, this is inefficient for large input lists because it performs a linear search on the list.
source share