So I have this list
X = [[1,2,3],[1,2,3],[1,2,3]]
How can I access all the last elements like Y = [3,3,3]?
Y=X[0:2][2] doesn't seem to work
I think a list comprehension would be the easiest way to do this. https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
Y = [i[-1] for i in X]
The -1 will get the last element of the lists. but this can be changed to get any element from these lists.
i[-1] to always get the last element.Y = [m[-1] for m in X]
The index -1 means the last element of a list.