enhancing slicing

Bengt Richter bokr at accessone.com
Thu Aug 23 15:55:13 EDT 2001


On Thu, 23 Aug 2001 15:21:47 +0200, "Alex Martelli" <aleax at aleax.it> wrote:

>"Roy Smith" <roy at panix.com> wrote in message
>news:roy-1DB49F.08271523082001 at news1.panix.com...
>> "Juan Valiño" <juanv at posta.unizar.es> wrote:
>> > My proposal is to introduce a new operator, for instance # (count):
>> > v[5 # 2]
>>
>> I don't see that this adds anything to the language that can't be done
>> already, other than being another way to do the same thing.
>
>Further, it's such an EASY thing to do -- the proposed
>    a[b # c]
>is EXACTLY the same as
>    a[b:b+c]
>so where's the added value to justify something as major
>as adding a new operator...?
>
I would rather have the alternative syntax
    a[b:+c]

but to anwer your question, I think Juan wanted not to
have to write a big expression twice with +c appended to
the second instance, especially if c were also a big expression.

Of course, he could write
    b = his.big.b.expression
    c = his.big.c.expression
first, and
    a[b:b+c]
as usual -- unless it was in a no-statements context where
elements of the expressions varied in value.

>I'd much rather have the modest implementation change to
>ensure that a[slice(b,b+c)] did just the same for all
>sequences -- it's a rather surprising thing that it fails!
>
Ok, out with it ;-)




More information about the Python-list mailing list