[Python-Dev] extended slicing for lists
Fri, 28 Jul 2000 23:57:22 -0700 (PDT)
On 28 Jul 2000, Michael Hudson wrote:
> >>> l = range(10)
> >>> l[2:10:2] = *5
> >>> l
> [0, 1, 0, 3, 0, 5, 0, 7, 0, 9]
Hmph. I'd be perfectly comfortable with
>>> l[2:10:2] = *5
TypeError: lists cannot assign to stepped slices
I can't see this being a commonly desired feature. If it
were perfectly clear what should happen in all cases, i'd
be okay with it -- but the ambiguity you get when the length
of the right side doesn't match the length of the indicated
slice is sufficient for me to suggest just dropping it:
better to avoid confusion altogether.
> (and presumably del l[a:b:c])
That seems reasonable and well-defined.
A separate question: does l[::-1] return l reversed? That is,
are the defaults for omitted start/end exchanged if step is
negative? This would seem to be quite useful -- having to say
l[len(l)-1:-1:-1] would be a royal pain.