[Tutor] counting a list of elements
karim.liateni at free.fr
Fri Apr 1 19:16:55 CEST 2011
I would like to get advice on the best practice to count elements in a
list (built from scractch).
The number of elements is in the range 1e3 and 1e6.
1) I could create a generator and set a counter (i +=1) in the loop.
2) or simply len(mylist).
I don't need the content of the list, indeed, in term of memory I don't
want to wast it. But I suppose len() is optimized too (C impementation).
If you have some thought to share don't hesitate.
More information about the Tutor