Appending to dictionary of lists
Alex van der Spek
zdoor at xs4all.nl
Tue May 3 15:50:31 EDT 2011
I open a csv file and create a DictReader object. Subsequently, reading
lines from this file I try to update a dictionary of lists:
csvf=open(os.path.join(root,fcsv),'rb')
csvr=csv.DictReader(csvf)
refd=dict.fromkeys(csvr.fieldnames,[])
for row in csvr:
for (k,v) in row.items():
refd[k].append(v)
I do not understand why this appends v to every key k each time.
Thanks in advance for any tips you can pass on.
Alex van der Spek
More information about the Python-list
mailing list