Getting Second-to-Last Element in List [duplicate]
I am able to get the second-to-last element of a list with the following:
>>> lst = ['a', 'b', 'c', 'd', 'e', 'f']
>>> print(lst[len(lst)-2])
e
Is there a better way than using print(lst[len(lst)-2])
to achieve this same result?
Solution 1:
There is: negative indices:
lst[-2]