You need to compare whether both lists result in the same Counter
.
>>> from collections import Counter
>>> list_a = ['one', 'two', 'three']
>>> list_b = ['three', 'one', 'two']
>>> Counter(list_a) == Counter(list_b)
True
>>> list_b = ['three', 'one', 'two', 'two']
>>> Counter(list_a) == Counter(list_b)
False
>>> set(list_a) == set(list_b)
True # False positive
Another solution would be to sort both lists and then compare them. The Counter
approach should be more efficient for big lists since it has linear time complexity (i.e. O(n)) while sorting is only pseudo-linear (i.e. O(n*log(n)).