As I noticed only after commenting on this answer , fragments in Python 3 return small copies of what they chop, not views. Why is this so? Even leaving aside the excessive use of views, rather than cutting copies, the fact that dict.keys , dict.values and dict.items all return views in Python 3 and that there are many other aspects of Python 3 that are more widely used by iterators, it seems that there would be a movement towards making the slices look alike. itertools has an islice function that makes iterative slices, but which is more limited than regular slicing, and does not provide dict.keys or dict.values line-of- dict.keys dict.values .
Also, the fact that you can use slice assignment to modify the original list, but the fragments themselves are copies, not representations, is a controversial aspect of the language and seems to violate some of the principles illustrated in Zen of Python .
That is, you can do
>>> a = [1, 2, 3, 4, 5] >>> a[::2] = [0, 0, 0] >>> a [0, 2, 0, 4, 0]
But not
>>> a = [1, 2, 3, 4, 5] >>> a[::2][0] = 0 >>> a [0, 2, 3, 4, 5]
or something like
>>> a = [1, 2, 3, 4, 5] >>> b = a[::2] >>> b view(a[::2] -> [1, 3, 5])
Seems somewhat arbitrary / unwanted.
I know http://www.python.org/dev/peps/pep-3099/ and the part that says: "Slices and extended slices will not disappear (even if the __getslice__ and __setslice__ APIs can be replaced), as well will not return views for standard object types. ", but the related discussion does not mention why it was decided to cut with views; in fact, most of the comments on this particular proposal from the proposals listed in the initial communication seemed to be positive.
What prevented the implementation of something similar in Python 3.0, which was specially designed so as not to be strictly compatible with Python 2.x and, thus, would be the best time to implement such a design change, and is there anything that could prevent it in future versions of Python?