PyNoob PyNoob - 1 year ago 113
Python Question

Getting Second-to-Last Element in List

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])

Is there a better way than using
to achieve this same result?

Answer Source

There is: negative indices:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download