我只是一个Python新手。 我有这个算法看看是不是一个词是回文。在我的算法中实现raw_input
def isPalindrome(s):
def toChars(s):
s = s.lower()
ans = ''
for c in s:
if c in 'abcdefghijklmnopqrstuvwxyz':
ans = ans + c
return ans
def isPal(s):
if len(s) <= 1:
return True
else:
return s[0] == s[-1] and isPal(s[1:-1])
return isPal(toChars(s))
我想实现这样的事情:
s=str(raw_input('Enter a word with quotes: '))
我想被要求输入一个字,因为现在,对我的代码运行的唯一方法是调用它的壳。
对话:对不起,我的英语。
'toChars'先后为总理候选人一个列表理解:'返回[c在s中如果c在'abcdefghijklmnopqrstuvwxyz'中]'。另外,您可能需要'string.lowercase'(可能包含á,具体取决于语言环境)。 – Eric
请不要编辑你的问题,要求完全不同的东西。我刚回到下面的答案实际上是回应的问题。 – Blckknght