You can use negative integers with the slicing operator for that. Here's an example using the python CLI interpreter:

>>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
>>> a[-9:]
[4, 5, 6, 7, 8, 9, 10, 11, 12]

the important line is a[-9:]

Answer from winsmith on Stack Overflow
Discussions

Is there an efficient way to check if the last n elements of a list are the same?
len(set(l[-n:]))==1 More on reddit.com
๐ŸŒ r/learnpython
11
2
August 31, 2020
How to fill remaining n values of list with 0 in python
can get [1, 0, 1, 0] by doing li = [int(x) for x in bin(10)[2:]]. How do I fill the remaining 28 values with 0s? If you are already using string representation (by invoking bin()) you can do [int(c) for c in f"{10:028b}"], where you can also forget about dropping the leading "0b" ([2:]) def f(x): return [int(c) for c in f"{x:028b}"] or def g(x, length): return [int(c) for c in f"{x:0{length}b}"] More on reddit.com
๐ŸŒ r/learnpython
17
11
October 6, 2019
Is it possible to grab the last element of a numpy array with a negative slice?
You can't loop from negative to postive slice values as they don't "wrap". a[-2:2] would also give an empty array. More on reddit.com
๐ŸŒ r/learnpython
8
1
December 15, 2021
Looping until the second to last element in a list, what's best practice?
for item in the_list[:-1] More on reddit.com
๐ŸŒ r/learnpython
23
3
January 11, 2024
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ python-get-last-n-elements-from-list-array
Python: Get Last N Elements from List/Array
July 17, 2022 - What if you omitted the ending index? In that case, Python will automatically assume you want to retrieve elements from the starting index to the end of the list. >>> arr = [1, 2, 3, 4, 5, 6] >>> arr[2:] [3, 4, 5, 6] ... No spam ever. Unsubscribe anytime.
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python get the last n elements of a list
Python Get the Last N Elements of a List - Spark By {Examples}
May 31, 2024 - How to get the last n elements of a list in Python? Getting the last n elements of a list in Python. You can use the slicing operator , where N is the
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ get-last-n-elements-from-given-list-in-python
Get last N elements from given list in Python
March 15, 2026 - from collections import deque days = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'] # Create deque with maxlen to keep only last 4 elements n = 4 last_n = deque(days, maxlen=n) print("Given list:", days) print(f"Last {n} elements:", list(last_n))
๐ŸŒ
Python Guides
pythonguides.com โ€บ get-the-last-n-elements-of-a-list-in-python
Get the Last N Elements of a List in Python
October 25, 2025 - Itโ€™s a clean, production-ready Python solution that I often use in my automation scripts. If you ever need the last N elements but in reverse order, you can combine reversed() with slicing. This is particularly useful when analyzing recent data first. sales = [1200, 1350, 1600, 1450, 1750, 1900, 2100, 2300] n = 4 last_sales = list(reversed(sales))[:n] print("Last", n, "sales values (reversed):", last_sales)
๐ŸŒ
TutorialKart
tutorialkart.com โ€บ python โ€บ how-to-get-the-last-n-elements-of-a-list-in-python
How to Get the Last N Elements of a List in Python
February 10, 2025 - In Python, you can retrieve the last N elements of a list using slicing, the deque from the collections module, or loops.
Find elsewhere
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-list-get-last-n-elements
Python List - Get Last N Elements
The negative index count from end of the list. Therefore [-N:] specifies the last N elements.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to get last n elements from a given list in python
5 Best Ways to Get Last N Elements from a Given List in Python - Be on the Right Side of Change
March 11, 2024 - If you have the number of elements โ€˜nโ€™ to be fetched at runtime and want to make it very explicit, you can use len(list) minus โ€˜nโ€™ to indicate the starting index. It is a slightly longer form but clearer to those new to Python. ... my_list = ['a', 'b', 'c', 'd', 'e'] n = 2 last_n_elements = my_list[-n:] if n <= len(my_list) else my_list print(last_n_elements)
๐ŸŒ
Medium
blog.toniflorithomar.com โ€บ how-to-get-the-first-or-last-n-elements-of-a-list-in-python-a-complete-guide-7ab28c68deb7
How to Get the First or Last N Elements of a List in Python โ€” A Complete Guide
March 15, 2025 - Learn how to efficiently extract the first or last N elements from a list in Python using slicing, deque, and islice for optimal performance
๐ŸŒ
ItSolutionstuff
itsolutionstuff.com โ€บ post โ€บ how-to-get-last-n-elements-of-a-list-in-pythonexample.html
How to Get Last n Elements of a List in Python? - ItSolutionstuff.com
October 30, 2023 - We can use [-N:] to get the last n elements of the python list. In this example, we will take myList variable with numbers of list. Then we will add n variable to get the last n number of items in the python list.
๐ŸŒ
HowToDoInJava
howtodoinjava.com โ€บ home โ€บ python โ€บ python: keep last n items of a list, array or string
Python: Keep Last N Items of a List, Array or String
March 6, 2024 - While Python lists donโ€™t have a built-in mechanism for maintaining a maximum length, we can achieve the same result using list slicing. Use this approach when the number of items to retain is relatively small. In this example, we use list slicing to obtain the last three items from the list.
๐ŸŒ
datagy
datagy.io โ€บ home โ€บ python posts โ€บ python: how to get the last item (or last n items) from a list
Python: How to Get the Last Item (or Last n Items) From a List โ€ข datagy
March 8, 2022 - Python lists begin at the 0th index, meaning that to get the first item, you would access index #0. Because of this, if you know how long a list is, you can access its last item by accessing that specific index.
๐ŸŒ
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().
๐ŸŒ
Moonbooks
en.moonbooks.org โ€บ Articles โ€บ How-to-slice-a-list-in-python-
How to slice a list in python ? - Moonbooks
August 7, 2021 - To get first n elements of a list in python a solution is to do mylist[-n:]. Example, extract only the first 3 elements: ... To get last n elements of a list in python a solution is to do mylist[-n:]. Example, extract only the last 2 elements:
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-list-slice-last-n-elements
Python List - Slice last N elements
To slice the last N element from a given list in Python, you can use negative indices with slicing. Negative indices count from the end of the list, so you can specify the range of elements you want to extract from the end.
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ bytes โ€บ python-accessing-the-last-element-of-a-list
Python: Accessing the Last Element of a List
August 24, 2023 - In the above example, my_list[-2:] gets the last two elements of the list. You can replace 2 with any number to get that many elements from the end of the list. The itertools module in Python comes with a function called islice() that can be used to get the last n elements of a list.