Adam DePrince wrote:
If your data is sparse you might want to consider using a dictionary
where the key is a tuple representing the coordinates.

a = {}
a[(0,0)] = 0
a[(0,1)] = 1
[snip]
print a.get( (5,0), None )

Good point. Note that you don't need the parentheses in the assignments or item accesses:


>>> a = {}
>>> a[0,0] = 10
>>> a[0,0]
10

Also note that you don't need to specify None as the default value when you call dict.get -- None is assumed if no default value is supplied:

>>> print a.get((5, 2))
None

Steve
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to