You can pre-select the list with:
l = [0] * 10000
which will be slightly faster than replaced by it (as it avoids intermediate redistributions). However, this usually allocates space for a list of pointers to whole objects that will be larger than an array of bytes in C.
If you need memory efficiency, you can use an array object. i.e:
import array, itertools a = array.array('b', itertools.repeat(0, 10000))
Please note that this can be somewhat slower to use in practice, since when accessing elements, the unboxing process occurs (they must first be converted to a python int object).
Brian source share