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).