Task: . Complete the following function that determines if two lists contain the same elements, but not necessarily in the same order. The function would return true if the first list contains 5, 1, 0, 2 and the second list contains 0, 5, 2, 1. The function would return false if one list contains elements the other does not or if the number of elements differ. This function could be used to determine if one list is a permutation of another list. The function does not affect the contents of either list.
My code:
def permutation(a,b):
if len(a) != len(b):
return False
n = len(a)
count = 0
for i in range(n):
for j in range(n):
if b[j] == a[i]:
count += 1
return count == n
def main():
lst_1 = [1,2,3,4]
lst_2 = [2,4,3,1]
lst_3 = [2,4,4,5,4,5]
lst_4 = [2,3,4,4,4,4]
print(permutation(lst_1,lst_2))
print(permutation(lst_2,lst_3))
print(permutation(lst_3,lst_4))
main()
permutation([2,2], [2,2])
which obviously should be True, and True (count==n==3) forpermutation([0,1,2], [1,2,2])
which should be False. \$\endgroup\$