Currently, I want to find the correct data structure to meet the following requirement.
There are multiple arrays with disordered element, for example,
[1, 2], [2, 1], [3, 2, 2], [2], [2, 1, 3], [2, 2, 3]
After processing those data, the result is,
[1, 2], [2, 2, 3], [2], [1, 2, 3]
With sorted element in each array and filter the duplicate arrays.
Here are my thoughts:
Data structure Set(Arrays)
? - Failed. It seems there is only one array in the build-in set
set([])
Data structure Array(Sets)
? - Failed. However, there is no duplicate element in the build-in set
. I want to know whether there is one data structure like multiset
in C++ within Python?
Set is a Data Structure in Python with an unordered and unindexed collection of elements. Every element in a Set is always unique. The Set Data Structure does not allow any duplication of elements.
The basic Python data structures in Python include list, set, tuples, and dictionary. Each of the data structures is unique in its own way. Data structures are “containers” that organize and group data according to type. The data structures differ based on mutability and order.
These structures are called List, Dictionary, Tuple and Set. Python allows its users to create their own Data Structures enabling them to have full control over their functionality.
A Python array is a little bit different to arrays in other programming languages in that it uses something called 'list' instead of array.
Transform your list to tuple(thus can be a item of set), then back to list.
>>> [list(i) for i in set([tuple(sorted(i)) for i in a])]
[[1, 2], [2], [2, 2, 3], [1, 2, 3]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With