测试列表或字符串是否为回文

4 python algorithm

我有一个最后的决定,老师说他打算在问题列表中加入一个回文检查器.基本上,我需要编写两个单独的函数,一个用于测试列表是否为回文(如果是,返回True),另一个用于测试字符串.

这是我到目前为止所拥有的.这似乎给了我麻烦:

def palindrome(s)
index = 0
index = True
     while index < len(s)        
        if n[index]==n[-1-index]
        index=1
        return True
     return False
Run Code Online (Sandbox Code Playgroud)

我不确定从哪里去.

jam*_*lak 9

对于列表或字符串:

seq == seq[::-1]
Run Code Online (Sandbox Code Playgroud)