嗨,我有一个列表中的字符串项目列表。我想看看这些字符串中的单词是否是使用函数的回文。
到目前为止我已经得到了这个密码
input_list = ['taco cat', 'bob', 'davey']
def palindromes(x):
for x in input_list:
if x == x[::-1]
return True
else:
return False
output = [palindromes(x)]
print(output)
结果应在列表中[真、真、假]
我在这里做错了什么
Tags:
您可能应该简化
palindromes
函数,以便只处理单个字符串:然后使用理解:
或者,使用
map
:尝试:
试试这个:
相关问题 更多 >
编程相关推荐