[EMAIL PROTECTED] wrote: > On May 31, 12:31 am, "Warren Stringer" <[EMAIL PROTECTED]> wrote: >> This is inconsistent: >> >> why does c[:][0]() work but c[:]() does not? >> Why does c[0]() has exactly the same results as c[:][0]() ? >> Moreover, c[:][0]() implies that a slice was invoked > > It's not inconsistent, but [:] probably does something different than > you think it does. All it does is create a copy (not in general, but > at least if c is a list or a tuple). Since in your example c is a > tuple and tuples are immutable, making a copy of it is essentially > useless. Why not just use the original? I.e. instead of c[:] you could > just write c. That's why c[:][0]() has exactly the same effect as c[0] > (), although the former is likely to be slightly slower.
An extremely minor point (and implementation specific), but while [:] will copy a list it won't copy a tuple. Likewise 'list(aList)' will always copy a list, 'tuple(aTuple)' won't copy a tuple. So in this particular example the slice is completely redundant. >>> c is c[:] is c[:][:][:][:] is tuple(c) True -- http://mail.python.org/mailman/listinfo/python-list