[Tutor] Speed of accessing list components

Glen Wheeler gew75 at hotmail.com
Sat Jun 26 23:55:31 EDT 2004

> At 08:08 AM 6/26/2004, Dragonfirebane at aol.com wrote:
> >[snip]
> >It seems to me that one easy(er) way of doing this would be:
> >
> >for i in l:
> >     print l[-i]
> >
> >which would achieve the same effect with no discernable slowdown and a
> >less awkward range.
> Only for the special case where the list consists of consecutive integers
> starting with 1.

  Also the ``slowdown'' I speak of is related to the [-i] usage.  This is
slower, in code, than regular indexing.
  Saving an external variable to use as the index is identical to my earlier
solution.  Except it uses a (tiny) bit more memory.
  I am personally in favour of Danny's suggestion.  It's also faster ;).


More information about the Tutor mailing list