🌐
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 - def get_second_last(items): if ... 'cherry', 'date'] second_last = fruits[len(fruits) - 2] print(second_last) ... Use list[-2] for the second-to-last element....
Discussions

Second to last element of the list
To find the second-to-last element of a list, we can use indexing techniques. In many programming languages, such as Python, negative indexing allows us to access elements from the end of the list. More on askfilo.com
🌐 askfilo.com
1
May 20, 2025
How to get the second last element of a list in C++ - Stack Overflow
i just started programing in C++, and have a little bit of experience in C, but in this program was trying to use the C++ libraries that i am not familiar to at all. The objective of the program is More on stackoverflow.com
🌐 stackoverflow.com
python accessing the second to the last element in a list - Stack Overflow
I have created a dictionary which I have assigned the first element of a list as a key. I would like to append the rest of the elements as values to the dictionary: file_a contains tab delimited ... More on stackoverflow.com
🌐 stackoverflow.com
HW7.15. Return the second to last element of a list In the function below, return the (single) element from the input list input_list which is in the second to last position in the list. Assume that the list is large enough. student.py 1 - def return_second_to_last_element(input_list):
Answer to HW7.15. Return the second to last element of a list More on chegg.com
🌐 chegg.com
1
October 13, 2020
🌐
Reddit
reddit.com › r/learnpython › looping until the second to last element in a list, what's best practice?
r/learnpython on Reddit: Looping until the second to last element in a list, what's best practice?
January 11, 2024 -

edit: forgot to mention I want the indeces not just the items

the methods I can think of are:

for i in range(len(arr) - 1)

for i, e in enumerate(arr[:len(arr) - 1])

I know range(len(arr)) is frowned upon, but I don't see how it's worse than enumerate in this case. In fact using enumerate on a shortened list and calling len to find the second to last element of that list seems extremely clunky and far less readable.

What's the best practice for doing this?

🌐
ItSolutionstuff
itsolutionstuff.com › post › python-get-second-last-element-of-list-exampleexample.html
Python Get Second Last Element of List Example - ItSolutionstuff.com
October 30, 2023 - you will do the following things for python array get second last element. In this example, I will create a simple list with the day with the name. Then I will get second last element with name using -2 key of array.
🌐
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:
Find elsewhere
🌐
YouTube
youtube.com › raptor analytics
Find 2nd last or nth last element of a list - YouTube
Find 2nd last or nth last element of a listGIT Link :https://github.com/Amritesh-kumar/Python-Basic/blob/main/Find 2nd last or nth last element%2
Published: October 13, 2023
Views: 247
🌐
How to Use Linux
howtouselinux.com › home › 3 ways to get last element of a list in python
3 Ways to Get Last Element of a List In Python - howtouselinux
October 9, 2025 - The most effective way to get the last element of a list in Python is using the list[-1]. Python allows you to use negative indices, which count from the end of the list instead of the beginning. So list[-1] gets the last element, list[-2] gets the second to last.
🌐
TutorialsPoint
tutorialspoint.com › How-to-get-the-last-element-of-a-list-in-Python
How to get the last element of a list in Python?
August 23, 2023 - In Python, getting the last element of a list is a common operation. There are several approaches to accomplish this task, each with different use cases and behaviors ? Python supports negative indexing, where -1 refers to the last element, -2 to the second-to-last, and so on.
🌐
Educative
educative.io › answers › how-to-find-the-second-last-element-of-sllist
How to find the second last element of SLList
The last node’s pointer is typically set to NULL to indicate the end of the list. ... To find the second last element, we must traverse the list until we reach the node just before the last node.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to get the last element of a python list?
How to Get the Last Element of a Python List? - Be on the Right Side of Change
September 27, 2020 - To access the last element of a Python list, use the indexing notation list[-1] with negative index -1 which points to the last list element. To access the second-, third-, and fourth-last elements, use the indices -2, -3, and -4.
🌐
CodeChef
codechef.com › learn › course › python-development › PYDEV18 › problems › PYTHPROB0759
Accessing the Second-Last Element in Python for project building
Option 1 · print("Second-last ... 2 Option 3Option 4 · Correct Answer: Option 1 · Explanation: Option A is correct because -2 refers to the second-last element, "indigo."...