initialize a dictionary
Sean Blakey
pythonista at gmail.com
Wed Mar 30 16:13:29 EST 2005
On 30 Mar 2005 13:02:05 -0800, shama.bell at gmail.com
<shama.bell at gmail.com> wrote:
> Hello,
>
> Can I do something like this?
>
> table = {}
> table[32, 16] = 0x0
>
> Where 32 specifies rows and 16 specifies columns and i am trying to
> initialize it to zero
>
> I should be able to do comparisons like:
> table[t1, t2] == 0x1 etc.
> -SB
>
Try it. It works. Sort of.
This code actually creates a dict named "table" mapping the key tuple
(32, 16) to the value 0x0. Note that you are NOT creating a
two-dimensional array, so this approach may be problematic if you ever
need to iterate values "by row" or "by column".
There is a python F.A.Q. on this, which you may find useful:
http://www.python.org/doc/faq/programming.html#how-do-i-create-a-multidimensional-list
--
Sean Blakey
Saint of Mild Amusement, Evil Genius, Big Geek
Python/Java/C++/C(Unix/Windows/Palm/Web) developer
quine = ['print "quine =",quine,"; exec(quine[0])"'] ; exec(quine[0])
More information about the Python-list
mailing list