"George Sakkis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Why does slicing a tuple returns a new tuple instead of a > view of the existing one, given that > tuples are immutable ? I ended up writing a custom > ImmutableSequence class that does this, but I > wonder why it is not implemented for tuples.
Numpy and Numarray both do this -- generate views into arrays -- because they are specifically aimed at large datasets for which the memory savings overrides the complications. Aside from the problem of not being able to delete the underlying object, the view object for a tuple would have to be a new type of object with a new set of methods. So there would be one more thing to learn. And so 'type(o) is tuple' would generally have to be replaced by 'isinstance(type(o), (tuple,tupleview)). For slices that are used within expressions and then discarded, a= (1,2,3) b = a(1:) + a(:1) an internal tuple view might be an interesting optimization. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list