More newbie help required with dictionaries
The following code only returns the last row(22) 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 = 11 machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] } machinekey = 22 machines = { machinekey:[0,1,0,0,0,0,0,0,0,0,0,0,0] } for machine in machines.keys(): print machine -- http://mail.python.org/mailman/listinfo/python-list
Re: More newbie help required with dictionaries
On Mon, Apr 16, 2007 at 06:43:37AM -0700, loial wrote: The following code only returns the last row(22) 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 = 11 machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] } machinekey = 22 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: More newbie help required with dictionaries
machines[machinekey] = [0,1,0,0,0,0,0,0,0,0,0,0,0] is what I needed...thanks On 16 Apr, 15:07, Christoph Haas [EMAIL PROTECTED] wrote: On Mon, Apr 16, 2007 at 06:43:37AM -0700, loial wrote: The following code only returns the last row(22) 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 = 11 machines = { machinekey:[1,0,0,0,0,0,0,0,0,0,0,0,0] } machinekey = 22 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 -- http://mail.python.org/mailman/listinfo/python-list