[Raymond Hettinger] > >List slice assignment is an example of a tool with a special case optimization > >for inputs that know their own length -- that enables the tool to pre-allocate > >its result rather than growing and resizing in spurts. Other such tools include > >tuple(), map() and zip().
[John Machin] > My reading of the source: if the input is not a list or tuple, a > (temporary) tuple is built from the input, using PySequence_Tuple() in > abstract.c. If the input cannot report its own length, then that > function resorts to "growing and resizing in spurts", using the > following code: > > if (j >= n) { > if (n < 500) > n += 10; > else > n += 100; > if (_PyTuple_Resize(&result, n) != 0) { > > Perhaps it could be changed to use a proportional increase, like > list_resize() in listobject.c, which advertises (amortised) linear > time. Check out the current source. The time machine beat you to it. Keep the faith, Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list