check if two arrays are equal in python
Code snippet on how to check if two arrays are equal in python
def comp(arr1, arr2):
if arr1 == None or arr2 == None:
return False
else:
arr1.sort()
arr2.sort()
return arr1 == arr2
This code is used to check if two Python arrays are equal. The function takes two arrays - arr1 and arr2 - as its argument and returns a boolean value. First, it checks if either array is None. This is important for cases where the user passes an empty array as an argument; if this was not checked, this would cause an error. Finally, the code sorts both arrays and compares them; if both sorted arrays are equal, then the two arrays are equal. If not, then the two arrays are not equal.