[Tutor] counting a list of elements

Knacktus knacktus at googlemail.com
Fri Apr 1 20:41:46 CEST 2011


Am 01.04.2011 19:16, schrieb Karim:
>
>
> 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.

Just a general suggestion: Provide code examples. I know most of the 
times you don't have code examples yet as you're thinking of how to 
solve your problems. But if you post one of the possible solutions the 
experienced guys here will very likely direct you in the proper 
direction. But without code it's hard to understand what you're after.

Cheers,

Jan


>
> Karim
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list