Suppose I've the following list:
list1 = [1, 2, 33, 51]
^
|
indices 0 1 2 3
How do I obtain the last index, which in this case would be 3, of that list?
indexinglistpython
Suppose I've the following list:
list1 = [1, 2, 33, 51]
^
|
indices 0 1 2 3
How do I obtain the last index, which in this case would be 3, of that list?
Best Answer
len(list1)-1
is definitely the way to go, but if you absolutely need alist
that has a function that returns the last index, you could create a class that inherits fromlist
.