【发布时间】:2017-07-23 09:04:43
【问题描述】:
这里我有一个单词列表:
[['r', 'o', 't', 'o', 'r'], ['e', 'v', 'e', 'i', 'a'], ['f', 'i', 'n', 'e', 'd'], ['e', 'n', 'e', 't', 'a'], ['r', 'a', 't', 'e', 'r']]
而且我必须显示此列表中的所有回文,它们在行和列中。 我已经编码以查找行中的所有回文。但无法实现在列中查找回文的方法。
到目前为止,这是我的代码:
result_1=""
if len(palindrome)==len_line_str:
for row in range(len(palindrome)):
for horizontal_line in range(len(palindrome[row])):
if ''.join(palindrome[row])==''.join(reversed(palindrome[row])):
result_1=''.join(palindrome[row])+" is a palindrome starting at ["+str(row)+"]["+str(row)+"] and is a row in the table"
print(result_1)
将显示输出:
rotor is a palindrome starting at [0][0] and is a row in the table
其中“转子”是回文。
我需要一种方法来获取以下列中的回文: “参考”、“信条”、“雷达”
非常感谢任何帮助。提前致谢!
【问题讨论】:
-
眼睛,如果你不明白我的回答,请告诉我,祝你好运!
标签: python list palindrome