The nice thing about Python is you don't have to build things from scratch,
and I imagine most people would discourage on account of it being a waste of
time, other then education value.

But the "best practice" in my humble opinion would be to use the built in
len function. If what you are after is to see how often 1e3 comes up in your
list, then you would use list.count('1e3').

In general, its best to use the python built ins.


On Fri, Apr 1, 2011 at 1:16 PM, Karim <[email protected]> wrote:

>
>
> Hello,
>
> 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.
>
> Karim
> _______________________________________________
> Tutor maillist  -  [email protected]
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to