Your first reaction to use
!= was the right one. Although the
ne works, it's not optimal, because the return value of
index (a number) and the
-1 are first converted to strings, and then compared. This is much slower than comparing the actual numbers.
Arjen