Why not just show the out-of-range index?

Russ uymqlp502 at sneakemail.com
Mon Dec 4 01:52:30 EST 2006


Dennis Lee Bieber wrote:

> 	OTOH: IndexError is something I seldom see -- most Python statements
> are intelligent enough to not need ad hoc indexing. About the only type
> that I've seen is just an, almost obvious, off-by-one problem...
>
> 	for i in xrange(len(a)):
> 		a[i] = a[i] + a[i+1]
>
> in which knowing the discrete values isn't that significant (to me, at
> least)
>
> 	It doesn't occur in things like
>
> 	for itm in a:

I agree that implicit indexing (your latter construct) is preferable to
explicit indexing if the index is not needed for any other purpose. But
sometimes the index itself is needed for some computation. And
sometimes a list is "randomly" accessed without a loop at all.




More information about the Python-list mailing list