Tuple slices

Bengt Richter bokr at oz.net
Wed Jan 26 05:43:53 EST 2005


On Wed, 26 Jan 2005 11:55:59 -0800, jfj <jfj at freemail.gr> wrote:

>Jeff Shannon wrote:
>
>> 
>> 
>> So, what problem is it, exactly, that you think you'd solve by making 
>> tuple slices a view rather than a copy?
>> 
>
>I think views are good for
>  1) saving memory
>  2) saving time (as you don't have to copy the elements into the new tuple)
>
>And they are worth it. However, (as in other cases with slicing), it is 
>very easy and fast to create a view for a slice with the default step 
>'1', while it's a PITA and totally not worth it to create a view for a 
>slice with non default step. I think it would be good to:
>
>  if slice_step == 1
>    create_view
>  else
>    create_new_tuple
>
>Actually, i think that slices with step, is a bad feature in general
>and i think I will write a PEP to suggest their removal in python3k.
>
What's the big deal with other than 1 steps? It is just adjusting a few numbers
so that you can either index the new virtual slice with an integer and return the
element, in which case the index into the original tuple will be
someoffset+i*somefactor once you get past the limit checks for the virtual
slice. By the same token, transforming a few numbers of one virtual slice
into similar numbers for a a new virtual slice of that shouldn't be rocket science.
And it wouldn't have to be done more than once.  Don't have time to do it now,
but there are plenty around here that could, I'm sure.

Regards,
Bengt Richter



More information about the Python-list mailing list