Possible Duplicate:
Cost of len() function
Does len() iterate over the objects in a list and then return their count? Thus giving it a O(n).
Or….
Does a python list keep a count of any objects that are appended to it and removed from it and then simply return this “count” when len() is called? Thus giving it O(1).
A Python list knows its own length;
lentakes O(1) time. Lists are actually arrays, not linked lists as in Lisp, wherelengthtakes linear time.