, :
def lists_equal_without_order(a, b):
"""
We don't care about duplicates in list comparison or the sublist comparison.
* [1,2,2] === [1,1,2] # True
* [[1,1], [1,1]] == [[1,1]] # True
The element lists are either the same length or we don't care about duplicates
* [1,1,1] === [1] # True
"""
for l1 in a:
check_list = frozenset(l1)
if not any(check_list.issuperset(l2) for l2 in b):
return False
return True
a = [[1,2], [3,4]]
b = [[4,3], [2,1]]
print lists_equal_without_order(a, b)
a = [[1,1], [2,2]]
b = [[1,2], [2,1]]
print lists_equal_without_order(a, b)
, :
def lists_equal_without_order(a, b):
"""
This will manipulate the original lists.
"""
for l1 in a:
l1.sort()
for l2 in b:
l2.sort()
if l1 == l2:
b.remove(l2)
break
else:
return False
return True
a = [[1,2], [3,4]]
b = [[4,3], [2,1]]
print lists_equal_without_order(a, b)
a = [[1,1], [2,2]]
b = [[1,2], [2,1]]
print lists_equal_without_order(a, b)
, , 2 :
from collections import Counter
def lists_equal_without_order(a, b):
"""
This will make sure the inner list contain the same,
but doesn't account for duplicate groups.
"""
for l1 in a:
check_counter = Counter(l1)
if not any(Counter(l2) == check_counter for l2 in b):
return False
return True
a = [[1,2], [3,4]]
b = [[4,3], [2,1]]
print lists_equal_without_order(a, b)
a = [[1,1], [2,2]]
b = [[1,2], [2,1]]
print lists_equal_without_order(a, b)