你题目的解答代码如下:
s = [
["A","F","K","P","U"],
["B","G","L","Q","V"],
["C","H","M","R","W"],
["D","I","N","S","X"],
["E","J","O","T","Y"]
]
def get_diag_se(s, ncols):
li = []
for i in range(ncols*2-1):
st = ""
for j in range(ncols):
m = ncols-1-i+j
if 0<=m<ncols:
st += s[j][m]
li.append(st)
return li
def get_diag_ne(s, ncols):
li = []
for i in range(ncols*2-1):
st = ""
for j in range(ncols):
m = i-j
if 0<=m<ncols:
st += s[j][m]
li.append(st)
return li
def find_words(s, ncols, wordlist):
li = []
for w in wordlist:
for v in s:
st = "".join(v)
if w in st:
li.append(w)
return li
print(get_diag_se(s, 5))
print(get_diag_ne(s, 5))
print(find_words(s, 5, ["JOT", "DOT", "DIN", "GIN"]))
如有帮助,望采纳!谢谢!