每当我尝试运行此代码时:
def isPalindrome( theSubList ):
theSubListtest = theSubList[0:]
if len(theSubListtest) <= 1:
return True
elif len(theSubListtest) == 2:
x = theSubListtest[0]
y = theSubListtest[1]
if (x == y):
return True
else:
return Falsefirst == theSubListtest.pop(0)
elif len(theSubListtest) > 2:
first = theSubListtest.pop(0)
last = theSubListtest.pop()
if first == last:
isPalindrome(theSubListtest)
else:
return False
candidatePs = [
[1,],
range(8),
range(4) + range(3,-1,-1),
range(4) + [0] + range(3,-1,-1),
range(3) + range(4) + [0] + range(3,-1,-1),
]
for p in candidatePs :
print p, isPalindrome( p )
它对 p 的前两个值正确运行,但随后为以下三个值输出“无”。任何帮助是极大的赞赏。提前致谢。