How to obtain the last index of a list?

前端 未结 7 1116
野的像风
野的像风 2021-02-01 16:16

Suppose I\'ve the following list:

list1 = [1, 2, 33, 51]
                    ^
                    |
indices  0  1   2   3

How do I obtain the

相关标签:
7条回答
  • 2021-02-01 16:50

    Did you mean len(list1)-1?

    If you're searching for other method, you can try list1.index(list1[-1]), but I don't recommend this one. You will have to be sure, that the list contains NO duplicates.

    0 讨论(0)
提交回复
热议问题