[Tutor] Speed of accessing list components

Glen Wheeler gew75 at hotmail.com
Fri Jun 25 20:17:09 EDT 2004


  Hi all,

  This is mainly for curiosity's sake, but when accessing a list component
using the -i method of indexing, in e.g.

>>> l
[1, 2, 3, 4, 5, 6]
>>> for i in range(1, len(l)+1):
..  print l[-i]
..
6
5
4
3
2
1

  is this exceptionally slow?  Or the preferred method?  In particular, I do
not want to reverse the list (this would add greater complexity to other
parts of the program) yet I don't really like the expression ``range(1,
len(l)+1)''.

  Thanks guys,
  Glen



More information about the Tutor mailing list