can I get the index number in for x in y loop?
Scott David Daniels
scott.daniels at acm.org
Mon Apr 3 12:50:17 EDT 2006
JuHui wrote:
> which one has best performance?
>
> a:for i in range(0,len(a))
> b:for x in a
> c:for x,y in enumerate(a)
Read up on the timeit module and figure it out for yourself.
The answer will depend on the distribution of your data.
> but, it seems I can't get index number with b format..:(
Well, that's true, but it is a bit like saying:
I cannot find the distance in meters between Paris and London with:
for i in range(10):
print i
--Scott David Daniels
scott.daniels at acm.org
More information about the Python-list
mailing list