More newbie help required with dictionaries

L

loial

The following code only returns the last row(222222) added to the
machines dictionary.
presumably I need some additional syntax to add rows to the dictionary
rather than overwrite.

What do I need to add?

machinekey = "111111"

machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] }

machinekey = "222222"

machines = { machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] }

for machine in machines.keys():
print machine
 
C

Christoph Haas

The following code only returns the last row(222222) added to the
machines dictionary.
presumably I need some additional syntax to add rows to the dictionary
rather than overwrite.

What do I need to add?

machinekey = "111111"

machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] }

machinekey = "222222"

machines = { machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] }

You redefine the "machines" dictionary here. So it just contains one
entry. What you mean:

machines.update({ machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] })

Or:

machines[machinekey] = [0,1,0,0,0,0,0,0,0,0,0,0,0]

Christoph
 
L

loial

machines[machinekey] = [0,1,0,0,0,0,0,0,0,0,0,0,0]

is what I needed...thanks



The following code only returns the last row(222222) added to the
machines dictionary.
presumably I need some additional syntax to add rows to the dictionary
rather than overwrite.
What do I need to add?
machinekey = "111111"
machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] }
machinekey = "222222"
machines = { machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] }

You redefine the "machines" dictionary here. So it just contains one
entry. What you mean:

machines.update({ machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] })

Or:

machines[machinekey] = [0,1,0,0,0,0,0,0,0,0,0,0,0]

Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,689
Members
48,796
Latest member
Greg L.

Latest Threads

Top