我正在编写一个函数,该函数需要返回列表列表中某个字符最后一次出现的行和列。如果该字符不在列表列表中,则该函数应返回 None。该函数忽略或跳过第一次出现,然后将最后一次出现的行和列作为有序对返回。
Example:
lst = [['.','.','.','e'],
['A','A','.','e'],
['.','.','.','e'],
['.','X','X','X'],
['.','.','.','.'],
['.','y','Z','Z']]
#For this list of lists the function should return (5,3) for Z since it is in the 6th list,
#and is the 6th value (python starts the count at 0) and for X it should return (3,3)
我认为我当前的代码找到了第一次出现的字符的行和列,但没有找到最后一次出现的字符。我如何指示 Python 忽略第一次出现而返回最后一次出现的行和列?
代码:
def get_far_end(symbol,lot):
for i in range(len(lot)):
for j in lot[i]:
if j == symbol:
return i ,lot[i].index(j)