[Tutor] On slicing
Rich Lovely
roadierich at googlemail.com
Thu Sep 17 14:12:41 CEST 2009
2009/9/17 george fragos <fragos.george at gmail.com>:
> If numbers=[1,2,3,4,5,6,7,8,9,10] and since "...any time the
> leftmost index in a slice comes later in the seqence than the second
> one... the result is always an empty sequence", why the slice
> numbers[10:0:-2] produces the sequence [10,8,6,4,2] but not the
> sequence []?
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
There should be a caveat to that: Unless the third index (step) is negative.
The first value is start, the second stop, and the third step. What
you are saying with numbers[10,0,-2], is start at 10 (facing towards
the end of the sequence), keep going until you get to 0, taking two
steps backwards each time.
I hope that clears things up a little..
--
Rich "Roadie Rich" Lovely
There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.
More information about the Tutor
mailing list