If you are actually using just single letters like shown in your example, then str.rindex would work handily. This raises a ValueError if there is no such item, the same error class as list.index would raise. Demo:

>>> li = ["a", "b", "a", "c", "x", "d", "a", "6"]
>>> ''.join(li).rindex('a')
6

For the more general case you could use list.index on the reversed list:

>>> len(li) - 1 - li[::-1].index('a')
6

The slicing here creates a copy of the entire list. That's fine for short lists, but for the case where li is very long, it may be more efficient to use a reverse iteration and avoid the copy:

def list_rindex(li, x):
    for i in reversed(range(len(li))):
        if li[i] == x:
            return i
    raise ValueError("{} is not in list".format(x))

One-liner version:

next(i for i in reversed(range(len(li))) if li[i] == 'a')
Answer from wim on Stack Overflow
🌐
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.
Discussions

Finding last index of some value in a list in Python
v[-1] is the last element of a list or tuple. v[-2] is the second last. The syntax where you're doing v[a:b:c], is known as slice notation. a is the start position, b is the end position, and c is the increment. a and b default to the start and end. c defaults to 1, so... v[::] refers to all elements from start to end. Useful for copying whole content somewhere, as distinct from assigning the list to a new variable. v[::2] refers to every second element v[::-1] is all the element in reverse. v[::-2] is every second element in reverse. v[5:] is all elements from 5 to the end. v[:5] is all elements from the start to < 5, so v[:5] and v[5:] do not overlap. More on reddit.com
🌐 r/learnpython
6
5
August 5, 2024
finding the last occurrence of an item in a list python - Stack Overflow
I wish to find the last occurrence of an item 'x' in sequence 's', or to return None if there is none and the position of the first item is equal to 0 This is what I currently have: def PositionL... More on stackoverflow.com
🌐 stackoverflow.com
python - How to find the last occurrence of item in nested list? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Ask questions, find answers and collaborate at work with Stack Overflow for Teams More on stackoverflow.com
🌐 stackoverflow.com
python - Find last occurence of item in a list excluding the last element - Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives ... Connect and share knowledge within a single location that is structured and easy to search. Learn more about Teams ... Correct answer provided for a single list iteration. ... What does last element mean, last element in the entire list, or last occurrence ... More on stackoverflow.com
🌐 stackoverflow.com
January 28, 2019
🌐
w3resource
w3resource.com › python-exercises › list › python-data-type-list-exercise-162.php
Python: Find the last occurrence of a specified item in a given list - w3resource
# Define a function called 'last_occurrence' that finds the last occurrence of a character 'ch' in a list of characters 'l1'. def last_occurrence(l1, ch): # Join the list of characters into a single string and find the last index of the character ...
🌐
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.

🌐
TutorialsPoint
tutorialspoint.com › article › last-occurrence-of-some-element-in-a-list-in-python
Last occurrence of some element in a list in Python
November 13, 2020 - # initializing the list words = ['eat', 'sleep', 'drink', 'sleep', 'drink', 'sleep', 'go', 'come'] element = 'sleep' # finding last occurrence by looping backwards final_index = -1 for i in range(len(words) - 1, -1, -1): if words[i] == element: final_index = i break print(f"Last occurrence of '{element}' is at index: {final_index}")
🌐
W3Schools
w3schools.com › python › ref_string_rfind.asp
Python String rfind() Method
Remove List Duplicates Reverse ... Server Python Syllabus Python Study Plan Python Interview Q&A Python Training ... The rfind() method finds the last occurrence of the specified value....
Find elsewhere
🌐
pythontutorials
pythontutorials.net › blog › how-to-find-the-last-occurrence-of-an-item-in-a-python-list
How to Find the Last Occurrence of an Item in a Python List: Simple Solutions for No Built-in Function — pythontutorials.net
Python lists are one of the most versatile and commonly used data structures, allowing you to store and manipulate sequences of items. A frequent task when working with lists is finding the **last occurrence** of a specific item—for example, identifying the highest index where a value like `2` appears in `[1, 2, 3, 2, 4]`. While Python provides built-in methods like `list.rindex()` to solve this directly, there are scenarios where you might need to implement this logic manually: perhaps you’re learning the fundamentals, preparing for a coding interview, or working in an environment with restricted access to built-in functions.
🌐
YouTube
youtube.com › pygpt
find last occurrence of element in list python - YouTube
Instantly Download or Run this code online at https://codegive.com Sure thing! Here's a tutorial on finding the last occurrence of an element in a Python lis...
Published: February 6, 2024
Views: 8
🌐
Sentry
sentry.io › sentry answers › python › get the last element of a list in python
Python Last Element in List Using Negative Indexing | Sentry
July 3, 2026 - Access the last element of a Python list using negative index notation with [-1], which counts positions from the end of the list instead of the start
🌐
GeeksforGeeks
geeksforgeeks.org › python-how-to-get-the-last-element-of-list
Get the Last Element of List in Python - GeeksforGeeks
May 10, 2025 - Explanation: Last element of the list l in the above example is 6. Let's explore various methods of doing it in Python: The simplest and most efficient method uses negative indexing with a[-1]. In Python, we can use -1 as an index to access ...
🌐
datagy
datagy.io › home › python posts › python list index: find first, last or all occurrences
Python List Index: Find First, Last or All Occurrences • datagy
February 28, 2022 - We’ll cover how to find a single item, multiple items, and items meetings a single condition. By the end of this tutorial, you’ll have learned: ... The Python list.index() method returns the index of the item specified in the list. The method will return only the first instance of that item.
🌐
Stack Overflow
stackoverflow.com › questions › 54395926
python - Find last occurence of item in a list excluding the last element - Stack Overflow
January 28, 2019 - Genius. I see what's happening here. The initial iteration creates a list of occurrences and finds the last one excluding the last element. You then reverse iterate the 2 occurrences lists to find first occurrence in reverse.
🌐
Finxter
blog.finxter.com › 5-best-ways-to-replace-the-last-occurrence-in-a-python-list
5 Best Ways to Replace the Last Occurrence in a Python List – Be on the Right Side of Change
February 16, 2024 - For example, given the list [3, ... article explores several methods to achieve this modification in Python. Enumerating a list in reverse order allows us to identify the last occurrence of an element. By using the enumerate() function alongside reversed(), we can iterate through ...