◐ Shell
clean mode source ↗

Message 183365 - Python tracker

> There's an obvious need for this, CPython uses optimizations like this
> internally, as does PyPy.

I don't know if it's a need or if it's just "nice to have".
By the way, in the list case it also makes C code simpler, since once
the list is preallocated you just have to call PyList_SET_ITEM to
populate it, and there's no error return to worry about.

Also, lists are easy to pre-allocate in pure Python as well:

l = [None] * N
# populate
for i in range(N):
    l[i] = ...