Take the 2-minute tour × list1 = [1, 2, 33, 51]  I need to check
is 4 the last index of the list. just like list1.lastIndex() #=>
3 how can I do it in python?  share|improve this question You
want the last element (list1[-1]) or the length of the array
(len(list1))? –  JMax Oct 25 '11 at 13:18 is there any other
method except len()? –  Sayuj Oct 25 '11 at 13:20 What's wrong
with len() that you want to find something else? –  Karl
Knechtel Oct 25 '11 at 13:24  4 Answers 4  up vote 3 down vote
accepted  len(list1)-1 is definitely the way to go, but if you
absolutely need a list that has a function that returns the last
index, you could create a class that inherits from list.  class
MyList(list):     def last_index(self):         return
len(self)-1  >>> l=MyList([1, 2, 33, 51]) >>> l.last_index()
share|improve this answer  Did you mean len(list1)-1? What's the
difference between decremented length and the index of last
element?  By the way, to say properly, the index of your last
element is 3, not 4. In most pro