enhancing slicing

Juan Valiño juanv at posta.unizar.es
Fri Aug 24 15:13:02 CEST 2001

Thank you very much for your interesting comentaries to my proposal v[a # b]
equivalent to v[a:a+b]

It's interesting that

v[a:][:b] is equivalent to v[a : a + b]  (for b>=0)
and therefore equivalent to my original (and wrong) proposal v[a # b]

However, the notation is something awful.
Also, I'm not sure (correct to me) if the performance is equal.

The classical solution:

a = something_complicated_expression
v[a : a + b] ...

is more boring and maybe not applicable in some contexts.

One of thinks I like most from Python is it elegance. It is my friend and
let me to expose my ideas simple and directly without the tricks and
difficulties that I found in some other languages. [You can see that with my
english :)  ]

I think that the idiom (initial position + size) is very common and we could
do more support to it in Python.

For that reason I insist in my idea and I wish that an suitable operator
exists for it (instead #).

The Icon-Tim Peters operators :+ and -: sounds well to me:

v[a +: b]  ==  v[a : a + b]
v[a -: b]  ==  v[a - b : a]

It has one aditional advantage: when I read the code I see directly if I
want to go to the right or to the left.

[Question: if b < 0, is the result empty?]

Could it affect previous code?
Is it easy to implement?.

(I think so, but I don't want to shout, remember the "comentary operator" :)

More information about the Python-list mailing list