len(list1)-1 is definitely the way to go, but if you absolutely need a list that has a function that returns the last index, you could create a class that inherits from list.

class MyList(list):
    def last_index(self):
        return len(self)-1


>>> l=MyList([1, 2, 33, 51])
>>> l.last_index()
3
Answer from Austin Marshall on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › finding last index of some value in a list in python
r/learnpython on Reddit: Finding last index of some value in a list in Python
August 5, 2024 -

Let's say v is a list or a tuple.

To find the last occurrence of value in v we would need to compute len(v) - 1 - v[::-1].index(value)

Why is this? Why must we subtract the last term from len(v) - 1? Why does simply writing v[::-1].index(value) give the wrong result?

In fact, what does v[::-1] actually do? Doesn't it reverse the list/tuple? If it does reverse it, then v[::-1].index(value) should give the last occurrence of value in v, but for some reason it does not work like that.

🌐
GeeksforGeeks
geeksforgeeks.org › python › python-last-occurrence-of-some-element-in-a-list
Last Occurrence of Some Element in a List - Python - GeeksforGeeks
July 11, 2025 - Using enumerate() allows us to loop through list while keeping track of both index and element. By checking for target element we can update index of its last occurrence efficiently.
🌐
Better Stack
betterstack.com › community › questions › how-to-get-last-element-in-list-in-python
How do I get the last element of a list in Python? | Better Stack Community
You can also use the len() function to get the length of the list and use it to index the last element. For example: ... Both of these approaches will work regardless of the length of the list.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-how-to-get-the-last-element-of-list
Get the Last Element of List in Python - GeeksforGeeks
July 11, 2025 - We can also find the last element by using len() function. Find length of the list and then subtracting one to get the index of the last element.
Find elsewhere
🌐
Sentry
sentry.io › sentry answers › python › get the last element of a list in python
Get the last element of a list in Python | Sentry
The Problem How do I get the last element of a list in Python? The Solution In Python, we can get the last element of a list using index notation. A positive…
Top answer
1 of 11
164

Sequences have a method index(value) which returns index of first occurrence - in your case this would be verts.index(value).

You can run it on verts[::-1] to find out the last index. Here, this would be len(verts) - 1 - verts[::-1].index(value)

2 of 11
50

Perhaps the two most efficient ways to find the last index:

def rindex(lst, value):
    lst.reverse()
    i = lst.index(value)
    lst.reverse()
    return len(lst) - i - 1
def rindex(lst, value):
    return len(lst) - operator.indexOf(reversed(lst), value) - 1

Both take only O(1) extra space and the two in-place reversals of the first solution are much faster than creating a reverse copy. Let's compare it with the other solutions posted previously:

def rindex(lst, value):
    return len(lst) - lst[::-1].index(value) - 1

def rindex(lst, value):
    return len(lst) - next(i for i, val in enumerate(reversed(lst)) if val == value) - 1

Benchmark results, my solutions are the red and green ones:

This is for searching a number in a list of a million numbers. The x-axis is for the location of the searched element: 0% means it's at the start of the list, 100% means it's at the end of the list. All solutions are fastest at location 100%, with the two reversed solutions taking pretty much no time for that, the double-reverse solution taking a little time, and the reverse-copy taking a lot of time.

A closer look at the right end:

At location 100%, the reverse-copy solution and the double-reverse solution spend all their time on the reversals (index() is instant), so we see that the two in-place reversals are about seven times as fast as creating the reverse copy.

The above was with lst = list(range(1_000_000, 2_000_001)), which pretty much creates the int objects sequentially in memory, which is extremely cache-friendly. Let's do it again after shuffling the list with random.shuffle(lst) (probably less realistic, but interesting):

All got a lot slower, as expected. The reverse-copy solution suffers the most, at 100% it now takes about 32 times (!) as long as the double-reverse solution. And the enumerate-solution is now second-fastest only after location 98%.

Overall I like the operator.indexOf solution best, as it's the fastest one for the last half or quarter of all locations, which are perhaps the more interesting locations if you're actually doing rindex for something. And it's only a bit slower than the double-reverse solution in earlier locations.

All benchmarks done with CPython 3.9.0 64-bit on Windows 10 Pro 1903 64-bit.

🌐
Finxter
blog.finxter.com › how-to-get-the-last-element-of-a-python-list
How to Get the Last Element of a Python List? – Be on the Right Side of Change
universe = ['u', 'n', 'i', 'v', 'e', 'r', 's', 'e'] # Access the n=4 last element from the list: n = 4 print(universe[:-n-1:-1]) # ['e', 's', 'r', 'e'] There are different points to consider in the code: You use a negative step size -1 which means that you slice from the right to the left. If you don’t provide a value for start, stop, or step indices, Python takes the default ones. For example, we don’t provide the start index and perform negative slicing so Python starts from the last element 'e'.
🌐
TutorialsPoint
tutorialspoint.com › How-to-get-the-last-element-of-a-list-in-Python
How to get the last element of a list in Python?
Input list: [5, 1, 6, 8, 3] Last element of the input list using len(list)-1 as index = 3 Last element of the input list using -1 as index = 3 · List slicing is a frequent practice in Python, and it is the most commonly utilized way for programmers to solve efficient problems.
🌐
Jessica Temporal
jtemporal.com › the-last-of-a-list-in-python
The last of the list with Python | Jessica Temporal
September 11, 2023 - Use the len() size function to get the length of the list and subtract 1 to get the index of the last element in that list. And that’s ok! It works. However, Python presents a more elegant way of doing this, see:
🌐
Quora
quora.com › How-do-I-find-the-last-element-of-a-list-in-Python
How to find the last element of a list in Python - Quora
Answer (1 of 3): > lets say we have a list of words [code]words = [‘One’, ‘Hello’, ‘Welcome’] [/code] * One Way to do this, is by counting the negative way. [code]print(words[-1]) # will print 'Welcome' (the answer you want) print(words[-2]) # will print 'Hello' print(words[-3]) ...
🌐
PyTutorial
pytutorial.com › last-element-of-array-python
PyTutorial | 3 Methods to Get Last Element of Array in Python
March 7, 2020 - To get the last element, you can use the index -1. Here's an example: my_array = [10, 20, 30, 40, 50] # Array last_element = my_array[-1] # Get Last Element print(last_element)
🌐
Python Shiksha
python.shiksha › home › tips › 7 ways to get the last element of a list in python
7 ways to Get the last element of a list in Python - Python Shiksha
August 1, 2022 - As we can see that we were able to get the last element by using the traversing the list in reverse order and fetching the first element of the reversed list. pop() is a very common and famous function in almost every language that can be used to delete the last element of an array, list etc.
🌐
30 Seconds of Code
30secondsofcode.org › home › python › first, last, initial, head, tail
First, last, initial, head, tail of a Python list - 30 seconds of code
May 15, 2024 - To get the last element of a list, you can use lst[-1]. This will return the last element of the list, or None if the list is empty.
🌐
PythonHow
pythonhow.com › how › get-the-last-element-of-a-list
Here is how to get the last element of a list in Python
my_list = [1, 2, 3, 4] # using the pop() method to remove and return the last element last_element = my_list.pop() # using slicing to get a copy of the last element last_element = my_list[-1:] Note that the pop() method only works if the list is not empty. If the list is empty, it will raise ...
🌐
Codecademy Forums
discuss.codecademy.com › frequently asked questions › python faq
What is the easiest way to access the last element of a list? - Python FAQ - Codecademy Forums
June 6, 2018 - Question Is there a way to find the last item in a list without using the len() function? Answer The last item in a list can be found using the index value computed by len() - 1 for the list.