"Fredrik Lundh" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Steven Bethard wrote:
>
> >>>>>a = 1, 2, 3
> >>>>>b = a[:]
> >>>>>a is b
> >> True
> >
> > My impression was that full tuple copies didn't actually copy, but that 
> > slicing a subset of a
> > tuple might.  Not exactly sure how to test this, but:
> >
> > py> a = 1, 2, 3
> > py> a[:2] is a[:2]
> > False
>
> yup.  and to figure out why things are done this way, consider this case:
>
>     >>> a = give_me_a_huge_tuple()
>     >>> len(a)
>     (a rather large number)
>     >>> b = a[:2]
>     >>> del a
>
> (IIRC, I proposed to add "substrings" when I implemented the Unicode string
> type, but that idea was rejected, for the very same "and how do you get rid of
> the original object" reason)
>
> </F>

Fair enough. So perhaps the question is whether such cases are more regular 
than something like:
a = give_me_a_huge_tuple()
slices = [a[i:j] for i in xrange(len(a)) for j in xrange(i+1, len(a)+1)]

George


-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to