Computer Science question (python list is slow with my cruddy algorithm )
eppstein at ics.uci.edu
Fri Aug 23 18:15:12 CEST 2002
In article <pan.2002.08.23.06.53.02.409701.2520 at charter.net>,
"Mr. Neutron" <nicktsocanos at charter.net> 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 ics.uci.edu http://www.ics.uci.edu/~eppstein/
More information about the Python-list