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

Jirka 'Eagle' Novak eagle at unicode.cz
Fri Aug 23 05:50:26 EDT 2002


> 	What I'd really like to do is figure out a way to represnt a
> 	2-dimensional world as a linear list.Then I could build a linear
> 	algorithm that generates the world and not have to use this
> 	list comprehensions to make lists of lists.

MATRIX_WIDTH = 32766
MATRIX_HEIGHT = 32766

for i in range(0, MATRIX_WIDTH * MATRIX_HEIGHT):
   array[i] = something

#to access an item at [x, y]:
print array[y * MATRIX_WITDH + x]

I'm not sure whether I understand well your problem, my english is 
rather poor. Also, i'm just a beginer in python.

Running multiple threads to populate the matrix could be a nice trick if 
you have a more than one CPU (assuming python wouldn't be against it ;-)).

You should also consider what percentage of items in the matrix is 
"nonempty".
-- 
Jirka 'Eagle' Novak
registered linux user #173581

E-Mail:   eagle at unicode.cz
ICQ:      46044619
HomePage: http://seal.unicode.cz/~eagle/




More information about the Python-list mailing list