By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,772 Members | 919 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,772 IT Pros & Developers. It's quick & easy.

initialize a dictionary

P: n/a
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

Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 30 Mar 2005 13:02:05 -0800, sh********@gmail.com
<sh********@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/progra...mensional-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])
Jul 18 '05 #2

P: n/a
The F.A.Q. does not explain how to create a 2 dimensional array and
initialize it to zero.

I need to iterate values by row and column as well.

I tried this....
w,x = 32, 16
A = [ [0x0]*w for i in range(x)]
print A
It does not create a 2 dimensional array with 32 rows and 16 columns

Thanks,
-SB

Jul 18 '05 #3

P: n/a
sh********@gmail.com wrote:
I need to iterate values by row and column as well.

I tried this....
w,x = 32, 16
A = [ [0x0]*w for i in range(x)]
print A


py> import numarray
py> print numarray.zeros((16, 8))
[[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 0]]

STeVe
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.