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

David Eppstein eppstein at
Fri Aug 23 18:15:12 CEST 2002

In article <pan.2002. at>,
 "Mr. Neutron" <nicktsocanos at> wrote:

> Now that that is out of the way, are there any better ways to represent
> the world than a list of lists? I just need to be able to say
> World[Y][X] = ( values ). Or be able to say what is at World[Position].
> Ideally I could say World[ (X,Y) ] = (Values) but I have not tried this.
> If World[ (X,Y) ] is empty, than it does not need to store anything in
> memory at all. I need to go to Idle now and experiment with this.

If much of your world is unpopulated or set to some default value that 
could be calculated by some function of its x,y coordinates, you could 
make World be a dictionary.  Then if World[x,y] exists it would tell you 
what is in that square, and if World[x,y] doesn't exist you could use 
your function to calculate what's there.  That way you can have a 
virtual 4Gb array the way you want, but only spend time examining the 
part you actually interact with.

David Eppstein       UC Irvine Dept. of Information & Computer Science
eppstein at

More information about the Python-list mailing list