Newbie: How do I implement an 2 element integer array in Python..?

Joshua Muskovitz josh at open.com
Wed Oct 11 21:45:21 EDT 2000


You silly people...  :-)  There is a much simpler way.  Use a dictionary!

MyArray = {}
MyArray[4,5] = 10
print MyArray[4,5]

of course, you might want to wrap this in a class to handle the case where
you reference a coordinate that you haven't stored yet.  But this will take
the least amount of space if you have a sparsely populated array.

MyArray.get( (x,y) , defaultValue) will also be safe, of course.

-- josh




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list