Python: Finding the last index of min element?

前端 未结 6 504
情书的邮戳
情书的邮戳 2021-01-12 05:20

For example [1,2,3,4,1,2]

has min element 1, but it occurs for the last time at index 4.

6条回答
  •  忘掉有多难
    2021-01-12 05:47

    a = [1,2,3,4,1,2]
    
    a.reverse()
    print len(a) - a.index(min(a)) - 1
    

    Update after comment:

    The side effect can be removed by reversing again (but of course that is quite inefficient).

    a.reverse()
    

提交回复
热议问题