0

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).

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
18818181881
  • 105
  • 7

1 Answers1

0

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])


DevScheffer
  • 491
  • 4
  • 15