This is a case where its up to the type involved. For example, xrange() slices the way you want but range() does not. Maybe a type would return for slices a proxy object that got the value by index or maybe it knows that it makes more sense to give you a copy because changes during the iteration should not be reflected in the iteration. It would be really easy to make a generic slicer.
On 9/15/07, James Stroud <[EMAIL PROTECTED]> wrote: > Hello all, > > I was staring at a segment of code that looked like this today: > > for something in stuff[x:y]: > whatever(something) > > and was wondering if the compiler really made a copy of the slice from > stuff as the code seems to suggest, or does it find some way to produce > an iterator without the need to make a copy (if stuff is a built-in > sequence type)? Or would it be more efficient to do the more clumsy (in > my opinion): > > for i in xrange(x, y): > whatever(stuff[i]) > > James > -- > http://mail.python.org/mailman/listinfo/python-list > -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list