习题8:它们一样吗?

Given two arrays a and b

Given two arrays a and b write a function comp(a, b) (compSame(a, b) in Clojure) that checks whether the two arrays have the "same" elements, with the same multiplicities. "Same" means, here, that the elements in b are the elements in a squared, regardless of the order.
def comp(array1, array2):
    # your code
    for i in array1:
        if i**2 not in array2 or array1.count(i) != array2.count(i**2):
            return False
    return True
def comp(array1, array2):
    return None in (array1, array2) and [i**2 for i in sorted(array1)] == sorted(array2)

你可能感兴趣的:(习题8:它们一样吗?)