I have a list like this:
animals = ['Goat', 'Tiger', 'Lion', 'Lion']
How can I find the maximum index of 'Lion'
?
expected result : 4
'Lion'
is in indices 3 and 4, and I want the maximum index (4).
I have a list like this:
animals = ['Goat', 'Tiger', 'Lion', 'Lion']
How can I find the maximum index of 'Lion'
?
expected result : 4
'Lion'
is in indices 3 and 4, and I want the maximum index (4).
Your index result is wrong, it's not 4 but 3
Animal = ['Goat', 'Tiger', 'Lion','a', 'Lion',1,5,'Lion',3]
Animal = ['Goat', 'Tiger', 'Lion', 'Lion']
def test(list1,word):
rev_list=list1[::-1]
idx_rev_list = rev_list.index(word)
list_len=len(list1)
res=list_len-idx_rev_list
return res-1
res=test(Animal,'Lion')
print(res)
print(Animal[res])