How to find Last occurrence of some element in a list in Python

1 Answer

0 votes
lst = ['php', 'python', 'c', 'c++', 'python', 'java', 'python', 'c', 'c#', 'java']
 
element = 'python'
 
lst.reverse()
 
index = lst.index(element)
 
print('index = ' , len(lst) - index - 1)
 
 
 
 
'''
run:
 
index =  6
 
'''

 



answered Sep 9, 2022 by avibootz
...