For example, I have a list
[0,2,2,3,2,1]
I want to find the index of the last '2' that appears in this list. Is there an easy way to do this?
For example, I have a list
[0,2,2,3,2,1]
I want to find the index of the last '2' that appears in this list. Is there an easy way to do this?
You can try the following approach. First reverse the list, get the index using L.index()
.
Since you reversed the list, you are getting an index that corresponds to the reversed, so to "convert" it to the respective index in the original list, you will have to substract 1
and the index from the length of the list.
n = ...
print len(L) - L[::-1].index(n) - 1