Iteration index

Aahz Maruch aahz at panix.com
Fri Jun 1 15:21:35 EDT 2001


In article <9f8pgk$11l6$1 at agate.berkeley.edu>,
E. Mark Ping <emarkp at CSUA.Berkeley.EDU> wrote:
>In article <mailman.991336497.10877.python-list at python.org>,
>D-Man  <dsh8290 at rit.edu> wrote:
>>
>>s = ('a', 'b', 'ala', 'a')
>>for i in xrange( len( s ) ) :
>>    print i , s[i]
>>
>>is easier to read, and you don't have the chance of forgetting to
>>increment the counter.
>
>Agreed.  But does it introduce n^2 complexity?  I can't find anything
>in the python docs that says that indexing into a list is O(1)--and
>most people assume that indexing into a list is O(n).

Dunno whether it's in the docs, but retrieving a list element is
definitely O(1).
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Androgynous poly kinky vanilla queer het Pythonista   http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"Characters exist to suffer, you know.  An author needs a little sadism
in her makeup."  --Brenda Clough



More information about the Python-list mailing list