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

Jirka 'Eagle' Novak eagle at
Fri Aug 23 11:50:26 CEST 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.


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 
Jirka 'Eagle' Novak
registered linux user #173581

E-Mail:   eagle at
ICQ:      46044619

More information about the Python-list mailing list