I'd like to efficiently compare two lists and determine if both share exactly the same elements.
The lists can be None, empty and of various lengths. Ordering of the elements inside the list does not matter, so ['a', 'b', 'c'] == ['a', 'c', 'b'] are equal in my case.
My current solution looks like this:
def list_a_equals_list_b(list_a, list_b):
if list_a != None and list_b != None:
if len(list_a) != len(list_b):
return False
else:
return len(frozenset(list_a).intersection(list_b)) == len(list_a)
elif list_a == None and list_b == None:
return True
else:
return False
Is there a more efficient way to compare those lists?
Thanks!