On 6 Nov, 13:12, kj <no.em...@please.post> wrote: > > The best I can come up with is this: > > arr = [None] * 1000000 > > Is this the most efficient way to achieve this result?
Yes, but why would you want to? Appending to a Python list has amortized O(1) complexity. I am not sure about Perl, but in MATLAB arrays are preallocated because resize has complexity O(n), instead of amortized O(1). You don't need to worry about that in Python. Python lists are resized with empty slots at the end, in proportion to the size of the list. On average, this has the same complexity as pre- allocation. -- http://mail.python.org/mailman/listinfo/python-list