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 - The last element is at index -1. products = ["Apples", "Pears", "Oranges"] last_product = products[-1] # will be "Oranges" Note that attempting to access the last element of an empty list will raise an IndexError exception.
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 - This function removes and returns the elements at the specified index from the list. If no value is provided, the default value is -1. It means that, by default, the pop() function returns the last element in the list in Python.
Find elsewhere
🌐
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
January 26, 2023 - To get the last element of a list in Python, you can use the negative indexing feature of the list data type.
🌐
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 - For lists with fewer than 2 elements, accessing [-2] raises an IndexError. Use a conditional check ? def get_second_last(items): if len(items) >= 2: return items[-2] else: return None # Test with different list sizes print(get_second_last([1, 2, 3, 4, 5])) # Has enough elements print(get_second_last([10])) # Only one element print(get_second_last([])) # Empty list
🌐
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
For example, given a list [1, 5, 6, 7, 4], the first element is 1 and the last element is 4, resulting in [1, 4].
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 - Input list: [5, 1, 6, 8, 3] Last element using for loop: 3 · Use list[-1] for getting the last element as it's the most pythonic and efficient approach.
🌐
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 - In this tutorial, we'll take a look at how to get the last element in a Python list with code examples and compare them to adhere to best coding practices.
🌐
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.