True
,但是当我运行它时,它似乎总是返回False
。检查361是否为361时似乎失败,但我无法弄清楚原因:def comp(array1, array2):
if array1 is None or array2 is None or len(array1) is 0 or len(array2) is 0 or len(array1) is not len(array2):
return False
aListSquared = [x * x for x in sorted(array1)]
array2.sort()
print(aListSquared)
print(array2)
for x in range(len(aListSquared)):
print('{0}:{1}'.format(aListSquared[x], type(aListSquared[x])))
print('{0}:{1}'.format(array2[x], type(array2[x])))
if int(aListSquared[x]) is not int(array2[x]):
return False
return True
a1 = [121, 144, 19, 161, 19, 144, 19, 11]
a2 = [11 * 11, 121 * 121, 144 * 144, 19 * 19, 161 * 161, 19 * 19, 144 * 144, 19 * 19]
print(comp(a1, a2))
有人可以告诉我我做错了什么,或者为什么验证似乎无法正常工作吗?
非常感谢
我下面有以下Python代码。我期望代码返回True,但是当我运行它时,它似乎总是返回False。检查361是否为361时似乎失败,但我无法弄清原因:...