preallocate list

Jim jbo at cannedham.ee.ed.ac.uk
Wed Apr 13 08:48:40 EDT 2005


Hi all

Is this the best way to preallocate a list of integers?
listName = range(0,length)

What about non integers?

I've just claimed in the newsgroup above that pre-allocating helps but I 
might be getting confused with matlab ;)

If I have a file with a floating point number on each line, what is the 
best way of reading them into a list (or other ordered structure)?

I was iterating with readline and appending to a list but it is taking ages.

Jim



More information about the Python-list mailing list