In Python, how do you get the last element of a list?
list[-1]
will retrieve the last element of the list without changing the list.
list.pop()
will retrieve the last element of the list, but it will mutate/change the original list. Usually, mutating the original list is not recommended.
Alternatively, if, for some reason, you're looking for something less pythonic, you could use list[len(list)-1]
, assuming the list is not empty.