On Fri, Mar 5, 2010 at 11:42 PM, Arnaud Delobelle <arno...@googlemail.com>wrote:
> Joan Miller <pelok...@gmail.com> writes: > > > What does a slice as [N::-1] ? > > > > It looks that in the first it reverses the slice and then it shows > > only N items, right? > > > > Could you add an example to get the same result without use `::` to > > see it more clear? > > > > Thanks in advance > > >>> l = range(10) > >>> l > [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] > >>> l[7::-1] > [7, 6, 5, 4, 3, 2, 1, 0] > >>> [l[i] for i in range(7, -1, -1)] > [7, 6, 5, 4, 3, 2, 1, 0] > >>> l = range(10) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> l[7::-1] [7, 6, 5, 4, 3, 2, 1, 0] >>> list(reversed(l))[-8:] [7, 6, 5, 4, 3, 2, 1, 0] ~l0nwlf
-- http://mail.python.org/mailman/listinfo/python-list