Verifique se é o último elemento na lista Python
if x == my_list[-1]:
# do what you want
Marton
if x == my_list[-1]:
# do what you want
l = [1,2,3,4,5]
last = l[len(l)-1]
lst = [2, 5 , 6, 3, 8, 9]
n = len(lst) #get the length
last_el = lst[n-1] #get the last element
print("The last element of the list is:", last_el)
some_list = [1, 2, 3]
some_list[-1]
print(some_list)
#Output = 3
list1 = ['a','b','c']
print(list1[-1])
import operator
# Python code to access the last element
# in a list using itemgetter() method
# Declaring and initializing list
number_list = [2, 1, 7, 4, 5, 3,6]
print ("List of elements are : " + str(number_list))
getLastElement = operator.itemgetter(-1)
# using [] operator to print last element
print("The last element of list using reverse method are : "
+ str(getLastElement(number_list)))