Computer Science question (python list is slow with my cruddy algorithm )

James Kew james.kew at btinternet.com
Sat Aug 24 00:28:34 CEST 2002


"Jirka 'Eagle' Novak" <eagle at unicode.cz> wrote in message
news:3D660562.9030503 at unicode.cz...
>
> MATRIX_WIDTH = 32766
> MATRIX_HEIGHT = 32766
>
> for i in range(0, MATRIX_WIDTH * MATRIX_HEIGHT):
>    array[i] = something

range will cost you another 4GB constructing a temporary list containing [0,
1, 2, ... 1073741824] to iterate over in order to populate the 4GB of array.
Use xrange for non-trivial iterations.

Others have commented that list is probably not a good fit to the OP's
requirement. I suspect when you're a beginner everything looks like a
list -- it was certainly that way for me! Now I'm a bit deeper in I'm
realising that often when I reach for list I'd be better off reaching for a
dict, or a class, or looking at the array module, or looking at Numeric.

--
James Kew
james.kew at btinternet.com





More information about the Python-list mailing list