using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
I'm really confused by what is happening here. If I use zip(), I can't update individual dictionary elements like I usually do. It updates all of the dictionary elements. It's hard to explain, so here is some output from an interactive session: In [52]: header=['a','b','c','d'] In [53]:

Re: using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
quick update, #change this line: for (k,v) in zip(header,[[]]*len(header)): #to this line: for (k,v) in zip(header,[[],[],[],[]]): and it works as expected. Something about the [[]]*len(header) is causing the weird behavior. I'm probably using it wrong, but if anyone can explain why that would

Re: using zip() and dictionaries

2009-04-30 Thread Chris Rebert
On Apr 30, 12:45 pm, Sneaky Wombat wrote: I'm really confused by what is happening here.  If I use zip(), I can't update individual dictionary elements like I usually do.  It updates all of the dictionary elements.  It's hard to explain, so here is some output from an interactive session:

Re: using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
quick update, #change this line: for (k,v) in zip(header,[[]]*len(header)): #to this line: for (k,v) in zip(header,[[],[],[],[]]): and it works as expected. Something about the [[]]*len(header) is causing the weird behavior. I'm probably using it wrong, but if anyone can explain why that would

Re: using zip() and dictionaries

2009-04-30 Thread Sneaky Wombat
Thanks! That certainly explains it. This works as expected. columnMap={} for (k,v) in zip(header,[[] for i in range(len(header))]): #print %s,%s%(k,v) columnMap[k] = v columnMap['a'].append('test') (sorry about the double post, accidental browser refresh) On Apr 30, 1:09 pm, Chris

Re: using zip() and dictionaries

2009-04-30 Thread Scott David Daniels
Sneaky Wombat wrote: quick update, #change this line: for (k,v) in zip(header,[[]]*len(header)): #to this line: for (k,v) in zip(header,[[],[],[],[]]): and it works as expected. Something about the [[]]*len(header) is causing the weird behavior. I'm probably using it wrong, but if anyone can

Re: using zip() and dictionaries

2009-04-30 Thread Arnaud Delobelle
Sneaky Wombat joe.hr...@gmail.com writes: I'm really confused by what is happening here. If I use zip(), I can't update individual dictionary elements like I usually do. It updates all of the dictionary elements. It's hard to explain, so here is some output from an interactive session:

Re: using zip() and dictionaries

2009-04-30 Thread Simon Forman
On Apr 30, 2:00 pm, Sneaky Wombat joe.hr...@gmail.com wrote: quick update, #change this line: for (k,v) in zip(header,[[]]*len(header)): #to this line: for (k,v) in zip(header,[[],[],[],[]]): and it works as expected.  Something about the [[]]*len(header) is causing the weird behavior.