Tuple slices

Peter Hansen peter at engcorp.com
Mon Jan 24 16:18:13 EST 2005

George Sakkis wrote:
> 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)]

I believe the general usage of tuples tends to mean that
"give_me_a_huge_tuple()" just doesn't happen except with
those who insist on using tuples as though they were nothing
other than read-only lists.

If you use a tuple the way it was apparently intended, you
are extraordinarily unlikely to find yourself with a
huge one requiring slicing in such a way that you care
whether it is a "view" or a new object.


More information about the Python-list mailing list