In Python, how do you get the last element of a list?
lst[-1] is the best approach, but with general iterables, consider more_itertools.last:
lst[-1]
Code
import more_itertools as mit mit.last([0, 1, 2, 3]) # 3 mit.last(iter([1, 2, 3])) # 3 mit.last([], "some default") # 'some default'