some_list[-1] is the shortest and most Pythonic.

In fact, you can do much more with this syntax. The some_list[-n] syntax gets the nth-to-last element. So some_list[-1] gets the last element, some_list[-2] gets the second to last, etc, all the way down to some_list[-len(some_list)], which gives you the first element.

You can also set list elements in this way. For instance:

>>> some_list = [1, 2, 3]
>>> some_list[-1] = 5 # Set the last element
>>> some_list[-2] = 3 # Set the second to last element
>>> some_list
[1, 3, 5]

Note that getting a list item by index will raise an IndexError if the expected item doesn't exist. This means that some_list[-1] will raise an exception if some_list is empty, because an empty list can't have a last element.

Answer from Sasha Chedygov on Stack Overflow
๐ŸŒ
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
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
Accessing the last element in a list in Python - Stack Overflow
I have a list for example: list_a = [0, 1, 3, 1] and I am trying to iterate through each number this loop, and if it hits the last "1" in the list, print "this is the last number in ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Neater way to access the last n elements in a vec?

You can use an endless range:

let vec = vec![1, 2, 3, 4, 5];
println!("Remaining: {:?}", &vec[2..]);

Prints: "Remaining: [3, 4, 5]"

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=8b1a03af4ae475b294030f3d5d43b5ad

More on reddit.com
๐ŸŒ r/learnrust
14
18
January 13, 2020
How to delete from a deque in constant time without "pointers"?

There's a technique which I call 'lazy popping' which can help here.

The idea is that you don't delete immediately from the queue. Rather, you leave deleted items in the queue, but mark them as deleted in another data structure -- usually a set. Whenever you have to pop an item to execute, keep popping until you reach an item that hasn't yet been deleted.

This gives you constant-time push, amortized constant-time pop (although you may pop multiple deleted items off the queue each time you pop an item to execute, each item only gets popped exactly once) , and constant-time deletion, which is better than what you can get by maintaining a list and deleting from start or middle.

In this case, you'd save the IDs of deleted items in the set. It looks like this (untested code):

import collections

class DeletableQueue:
    def __init__(self):
        self.deleted = set()
        self.queue = collections.deque()
    def push(self, item):
        self.queue.append(item)
    def pop(self):
        # Precondition: there is at least one non-deleted item on the queue.
        while id(q[0]) in deleted:
            q[0].pop_left()  # Discard an already-deleted item.
        return q.pop_left()  # Return the actual item to pop
    def delete(self, item_to_delete):
        self.deleted.add(id(item_to_delete))
More on reddit.com
๐ŸŒ r/learnpython
15
6
October 20, 2014
๐ŸŒ
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 - The simplest and most efficient method uses negative indexing with a[-1]. In Python, we can use -1 as an index to access the last element directly. ... We can also find the last element by using len() function.
๐ŸŒ
Jessica Temporal
jtemporal.com โ€บ the-last-of-a-list-in-python
Getting the last element of a list in Python | Jessica Temporal
June 20, 2026 - Coming from other languages like ... get the last element of a list: 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....
๐ŸŒ
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.

๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ last element in list python
Program to Get the Last Element in List in Python - Scaler Topics
May 18, 2023 - Using negative indexing is a very efficient solution to get the last element from the list, even if the size of the list is large. The list[-n] gives the nth-to-last element of the list. In Python, the list class provides a method pop().
Find elsewhere
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-get-the-second-to-last-element-of-a-list-in-python
How to get the second-to-last element of a list in Python?
March 15, 2026 - Python lists support negative indexing, where -1 refers to the last element and -2 refers to the second-to-last element. This makes accessing elements from the end of a list straightforward.
๐ŸŒ
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 first element of a list ... first([1, 2, 3]) # 1 first([]) # None ยท 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....
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-get-last-n-elements-from-given-list
Python | Get Last N Elements from Given List - GeeksforGeeks
Time Complexity: O(n), where n is the length of the list test_list Auxiliary Space: O(n) additional space of size n is created where n is the number of elements in the list ยท This code extracts the last N elements from a list. It first reverses the list using slicing ([::-1]), then iterates over the first N elements, appending them to a new list res.
Published: July 11, 2025
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-get-first-and-last-elements-of-a-list
Get first and last elements of a list in Python - GeeksforGeeks
List comprehension can be used to pick specific positions from a list. You can get the first and last elements using [a[i] for i in (0, -1)]. This method works well but is less readable compared to indexing.
Published: July 11, 2025
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ remove-last-element-from-list-python
Remove Last Element from List in Python | FavTutor
October 12, 2023 - Learn how to delete the last element of a Python list using the pop(), slicing, del, and list comprehension methods.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-get-the-last-element-of-a-list-in-python
How to get the last element of a list in Python?
March 24, 2026 - This approach iterates through the list and identifies the last element by checking if the current index equals len(list) - 1.
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-get-last-element-in-list
How To Get The Last Element Of A List In Python?
March 19, 2025 - By using states[-1] we retrieve the last element of the list, which is โ€œIllinoisโ€. ... Another approach to get the last element is by using the len() function in combination with indexing. Python len() function returns the length of the list, and by subtracting 1 from it, you can obtain ...
๐ŸŒ
Quora
quora.com โ€บ How-will-you-remove-the-last-object-from-a-list-in-Python-1
How will you remove the last object from a list in Python? - Quora
Answer (1 of 2): In Python list has two functions remove() and pop() which can help you to remove last object. Method 1: Using remove() function Syntax: lst.remove(lst[-1]) Explanation: Remove function accepts the object as a parameter for it to remove. Hence we specify lst[-1] which returns t...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ python-get-last-n-elements-from-list-array
Python: Get Last N Elements from List/Array
July 17, 2022 - One common use case is to retrieve N elements from the end of a list/array, which we'll show how to do here. In Python, you can retrieve elements using similar syntax as in many other languages, using brackets ([]) and an index. However, this syntax can be extended to optionally specify both ...
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ python โ€บ standard library โ€บ list โ€บ pop()
Python List pop() - Remove Last Item
November 5, 2024 - Explore various scenarios where ... involving conditional removals. Ensure you have a non-empty list. Use the pop() method to remove the last item. ... This example demonstrates removing the last item, 'cherry', from the ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ python-get-last-element-in-list
Python: Get Last Element in List
March 2, 2023 - ... The first element has the index of 0, the second has the index of 1, and the nth element has an index of n-1. The negative indexing follows the same logic, but in reversed order. The last element has the index of -1, the second to last element has the index of -2, and so on:
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-remove-last-k-elements-of-list
Remove last K elements of list - Python - GeeksforGeeks
July 11, 2025 - By using a loop and calling pop() K times, we can effectively remove the last K elements. This method modifies the list in place repeatedly.