[Python-ideas] improvements to slicing

spir denis.spir at gmail.com
Wed Oct 6 22:39:11 CEST 2010


On Wed, 06 Oct 2010 14:21:03 -0500
Ron Adam <rrr at ronadam.com> wrote:

> 1. Have the direction determine by the start and stop values rather than 
> than by the step value so that the following is true.
> 
>     "abcdefg"[start:stop:step] == "abcdefg"[start:stop][::step]

Please provide an example with current and proposed semantics.
If I understand correctly, this does not work in practice. When range bounds are variable (result from computation), the upper one can happen to be smaller than the upper one and we just want the resulting sub-sequence to be empty. This is normal and common use case, and this is good. (upper <= lower) ==> []
Else many routine would have to special-case (upper < lower).
Your proposal, again if I understand, would break this semantics, instead returning a sub-sequence in reverse order.


Denis
-- -- -- -- -- -- --
vit esse estrany ☣

spir.wikidot.com




More information about the Python-ideas mailing list