This can be written as a function indexes()
and then take the max()
of the resulting iterator:
Example:
def indexes(xs, value):
for i, x in enumerate(xs):
if x == value:
yield i
a = [2, 2, 4, 2, 5, 7]
print max(indexes(a, min(a))) # 3
Update; Just as a matter of completeness; if you per se wanted the minimum index for a set of values with more than one minimum you'd just swap out max()
for min()
at the front of the expression. So:
a = [2, 2, 1, 4, 2, 1, 5, 7]
print min(indexes(a, min(a))) # 2
whilst:
print max(indexes(a, min(a))) # 5
This is kind of handy and flexible in general :)