Answered by : marton
if x == my_list[-1]: # do what you want
Source : https://stackoverflow.com/questions/39808908/detect-if-item-is-the-last-in-a-list | Last Update : Fri, 04 Sep 20
Answered by : inexpensive-ibis-a7frp9umptpo
list1 = ['a','b','c']
print(list1[-1])
Source : | Last Update : Mon, 13 Jul 20
Answered by : condemned-cottonmouth-r09evjmg2z3q
some_list = [1, 2, 3]
some_list[-1]
print(some_list)
#Output = 3
Source : https://stackoverflow.com/questions/930397/getting-the-last-element-of-a-list | Last Update : Sat, 02 May 20
Answered by : fancy-fly-dmsmzj9cmsen
your_list = ["apple", "orange", "grapes"]
last_value = your_list[-1]
Source : | Last Update : Mon, 29 Jun 20
Answered by : tired-toad-hvs3497x7uf2
>>> 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]
Source : https://stackoverflow.com/questions/930397/getting-the-last-element-of-a-list | Last Update : Wed, 13 May 20
Answered by : david-cao
list1 = [1, 2, 3, 4, 5]
print(list1[len(list1)-1])
print(list1[-1])
print(list1.pop())
Source : https://www.howtouselinux.com/post/get-last-element-of-a-list-in-python | Last Update : Sat, 12 Mar 22
Answered by : aggressive-ant-jg3vj2xka88m
MyList = [1, 2, 3, 4, 5]
print(MyList[len(Mylist)-1])
# Makes you look professional
Source : | Last Update : Fri, 29 Jan 21
Answered by : david-cao
data = ["infy", "tcs", "affle", "dixon", "astral"]
last_element = data[-1]
print(last_element)
Source : https://www.howtouselinux.com/post/get-last-element-of-a-list-in-python | Last Update : Sun, 29 May 22
Answered by : collins-emasi
# You can index using -1 to get the last item on the list
names = ['collins', 'emasi', 'sam']
l_item = names[-1]
# Output: sam
Source : | Last Update : Wed, 02 Mar 22