How can I uniquify the following list in Python:
all_the_ways = [(5,), (2, 2, 1), (2, 1, 2), (2, 1, 1, 1), (1, 2, 2),\
(1, 2, 1, 1), (1, 1, 2, 1), (1, 1, 1, 2), (1, 1, 1, 1, 1)]
Desired output is:
[(5,), (2, 2, 1), (2, 1, 1, 1), (1, 1, 1, 1, 1)]
i.e. I need to get rid of tuples that have the same set of numbers but in different order.
I tried
set(all_the_ways)
but it only transpose elements.
And when I do
list(map(set, all_the_ways))
the things getting only worse:
[{5}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1}]
In other words I need to convert inner tuple to a collection that allows multiple equal items (set
is not suitable) and for which permutations of elements don't change the collection itself (kinda like C++'s multiset
)