You can simply use slice notation to skip the last element:

for i, (a, b) in enumerate(list_of_tuples[:-1]):

Below is a demonstration:

>>> lst = [1, 2, 3, 4, 5]
>>> lst[:-1]
[1, 2, 3, 4]
>>> for i in lst[:-1]:
...     i
...
1
2
3
4
>>>
Answer from user2555451 on Stack Overflow
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-list-without-last-element
Python List without Last Element
To get Python List without last element, you can use slicing with list[:-1] or use pop() method without any argument. Slicing returns a new list without last element, while pop() removes last element from list. In this tutorial, we write example programs for each of these processes to get list ...
Discussions

python - How to loop through all but the last item of a list? - Stack Overflow
1 Is it possible to ignore the last element of a list without having to create another list and without modifing the original list? -1 Loop over list items, except for the last two items (python) More on stackoverflow.com
๐ŸŒ stackoverflow.com
List Comprehension - Ignore Last Item
Ultimately, this seems like a bit of an xy problem. What is the bigger picture use case? More on reddit.com
๐ŸŒ r/learnpython
14
1
February 9, 2022
python - Remove the last N elements of a list - Stack Overflow
Also helps educate people new to Python. Anyone can feel free to use any solution, so its good we have a variety 2017-12-31T23:06:01.83Z+00:00 ... This should be the accepted answer imo, it does not create a new list, and @jamylak correctly pointed out to check for n >= 1 2020-05-06T06:58:51.69Z+00:00 ... Save this answer. ... Show activity on this post. if you wish to remove the last n elements... More on stackoverflow.com
๐ŸŒ stackoverflow.com
How do I remove an element from the end of a list without returning the value? (Python)
Can't you just ignore the returning value...? More on reddit.com
๐ŸŒ r/learnprogramming
5
2
April 30, 2021
๐ŸŒ
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.
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ python โ€บ remove the last element from a python list
Remove the last element from a Python list | Techie Delight
July 7, 2026 - This can be done using the expression l = l[:-1], where l is your list. l[:-1] is short for l[0:len(l)-1]. ... Note that this function doesnโ€™t raise any error on an empty list but constructs a copy of the list, which is not recommended.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python print list without last element
Python Print List Without Last Element - Be on the Right Side of Change
October 8, 2022 - Hereโ€™s a simple example that prints the list without the last element 'Dave' using slicing: lst = ['Alice', 'Bob', 'Carl', 'Dave'] print(lst[:-1]) # ['Alice', 'Bob', 'Carl'] ๐Ÿ’ก Recommended Tutorial: An Introduction to Python Slicing
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-traverse-list-except-last-element
Traverse List except last element
To traverse through list except for the last element, we have to check the condition if the index is less than the list length by one, and stop traversing when the condition fails. source_list = [8, 4, 7, 3, 6, 1, 9] index = 0 while index < len(source_list) - 1: print(source_list[index]) index ...
๐ŸŒ
EyeHunts
tutorial.eyehunts.com โ€บ home โ€บ python list without last element | example code
Python list without last element | Example code - EyeHunts
January 20, 2022 - But a better way is to delete the item directly, using the del keyword. ... Do comment if you have any doubts and suggestions on this list tutorial. ... All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-list-slice-all-but-last
Python List - Slice all but last element
To slice all elements from a given list but excluding the last element in Python, you can use either slice the list from starting to length of the list minus one, or use a negative index of -1 for the stop index.
Find elsewhere
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ remove-last-element-from-list-in-python
Remove Last Element from List in Python - GeeksforGeeks
July 12, 2025 - del operator allows removal of list elements by index. To delete the last element, del list[-1] is used, which directly modifies the original list by removing its last item without returning it.
๐ŸŒ
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 - def last(lst): return lst[-1] if lst else None last([1, 2, 3]) # 3 last([]) # None ยท To get all elements of a list except the last one, you can use lst[:-1]. This will return all elements of the list except the last one, or an empty list if ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python-remove-last-k-elements-of-list
Remove last K elements of list - Python - GeeksforGeeks
January 18, 2025 - a[:-k] takes all elements from the start of the list to the K-th last element, effectively removing the last K elements. If K is zero, it returns the original list without modification.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ list comprehension - ignore last item
r/learnpython on Reddit: List Comprehension - Ignore Last Item
February 9, 2022 -

I have a list of NamedTuples (short extract below) and am using list comprehension to add a random value to the a and b values in all the NamedTuples called "Test".

That works ok but I would like to exclude the last Test NamedTuple so instead of adding the random value it leaves the values as they were originally.

There may be other NamedTuples after the last Test NamedTuple.

Is this possible?

Extract:

list_one = [Test(a=820, b=625, time=1643282249.9990437), Test(a=820, b=624, time=1643282250.0470896), Test(a=820, b=623, time=1643282250.1034527), Pass(test_type='do1', pass='ffg3', time=1643282250.7834597)]

Code:

randomise = lambda: random.randint(-5, 5)
list_one = [Test(t.a + randomise(), t.b + randomise(), t.time) if isinstance(t, Test) else t for t in list_one]
๐ŸŒ
TechBeamers
techbeamers.com โ€บ python-remove-last-element-from-list
Python Remove Last Element from List - TechBeamers
November 30, 2025 - If you need both an in-place operation and a new list without the last element, consider using the extend() method as it offers a balance between performance and readability. In summary, the choice of method depends on your specific requirements, such as whether you need to modify the original list, preserve it, or obtain the value of the removed element. By understanding these methods and their trade-offs, you can effectively remove the last element from a list in Python ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ python โ€บ python list remove last element
Python List Remove Last Element - Spark By {Examples}
May 31, 2024 - How to remove the last element/item from a list in Python? To remove the last element from the list, you can use the del keyword or the pop() method.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-program-to-remove-the-last-element-from-list
Python program to Remove the last element from list - GeeksforGeeks
July 23, 2025 - Pop() function is better but the problem with that is it removes the elements permanent and we can never get it back. So, for this python has a special feature of slicing where we can directly prints the list except last element.
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ remove last element from list python
Remove last element from list python - Java2Blog
February 24, 2021 - Please note that list.pop() returns the remove element, but del statement does not return the removed element. It raises IndexError if list is empty as it is trying to access an index that is out of range. We can also use slicing to remove the last element.
๐ŸŒ
TheLinuxCode
thelinuxcode.com โ€บ home โ€บ remove the last element from a list in python (without surprises)
Remove the Last Element from a List in Python (Without Surprises) โ€“ TheLinuxCode
February 1, 2026 - \n\nIf you run that, both tasks and alias print without the last item. Thatโ€™s not โ€œPython being weirdโ€; itโ€™s your code mutating shared state.\n\nSo before picking a method, I ask one question: Should this operation change the original list object? If yes, I default to pop() or del. If no, I default to slicing.\n\n## The default I recommend: pop() (mutates and returns the removed item)\nIf Iโ€™m removing the last element from a list in day-to-day Python, I almost always reach for list.pop().\n\nWhy?
๐ŸŒ
Quora
quora.com โ€บ What-would-be-the-best-approach-to-remove-the-last-item-number-from-a-list-while-iterating-in-Python
What would be the best approach to remove the last item (number) from a list while iterating in Python? - Quora
Answer (1 of 7): The pop() method will remove the last item from a list, regardless of its type. Here is an example showing iteration until the list is empty: [code]>>> nums = [4, 5, 13, -1, 17, 29] >>> while nums: ... print('just removed', nums.pop()) ... just removed 29 just removed 17 ju...