[Python-Dev] extended slicing for lists
29 Jul 2000 10:07:43 +0100
The patch is here, btw:
Ka-Ping Yee <firstname.lastname@example.org> writes:
> 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.
Well, the BDFL spoke.
> > (and presumably del l[a:b:c])
> That seems reasonable and well-defined.
> A separate question: does l[::-1] return l reversed?
Yes. All that cleverness is in PySlice_GetIndices, so this patch gets
it for free.
> 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.
Well, you could probably always say
(your example returns the empty list!) but yes, I think l[::-1] is one
of the neater bits of new behaviour.
"declare"? my bogometer indicates that you're really programming
in some other language and trying to force Common Lisp into your
mindset. this won't work. -- Erik Naggum, comp.lang.lisp