Re: Appending to dictionary of lists

2011-05-03 Thread Alex van der Spek
Thank you! Would never have found that by myself. "Paul Rubin" wrote in message news:7x7ha75zib@ruckus.brouhaha.com... "Alex van der Spek" writes: refd=dict.fromkeys(csvr.fieldnames,[]) ... I do not understand why this appends v to every key k each time. You have initialized every el

Re: Appending to dictionary of lists

2011-05-03 Thread Dan Stromberg
On Tue, May 3, 2011 at 12:56 PM, Paul Rubin wrote: > "Alex van der Spek" writes: > > refd=dict.fromkeys(csvr.fieldnames,[]) ... > > I do not understand why this appends v to every key k each time. > > You have initialized every element of refd to the same list. Try > >refd = dict((k,[]) fo

Re: Appending to dictionary of lists

2011-05-03 Thread Paul Rubin
"Alex van der Spek" writes: > refd=dict.fromkeys(csvr.fieldnames,[]) ... > I do not understand why this appends v to every key k each time. You have initialized every element of refd to the same list. Try refd = dict((k,[]) for k in csvr.fieldnames) instead. -- http://mail.python.org/mai