リストのリストで特定の文字が最後に出現した行と列を返す必要がある関数を作成しています。文字がリストのリストにない場合、関数は 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)