I found many different ways of getting the last element from a list in python
alist[-1]
alist[len(alist) -1]
Which is the way you would do this?
I found many different ways of getting the last element from a list in python
alist[-1]
alist[len(alist) -1]
Which is the way you would do this?
someList[-1]
is the shortest and most Pythonic. Why complicate things by adding an unnecessary function call in there?
You can also do:
alist.pop()
It depends on what you want to do with your list because the pop() method will delete the last element.
For guidance on issues such as this one, type this at the python prompt:
import this