Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #4571
| From | Paul Rubin <no.email@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Appending to dictionary of lists |
| References | <4dc05c8b$0$41117$e4fe514c@news.xs4all.nl> |
| Date | 2011-05-03 12:56 -0700 |
| Message-ID | <7x7ha75zib.fsf@ruckus.brouhaha.com> (permalink) |
| Organization | Nightsong/Fort GNOX |
"Alex van der Spek" <zdoor@xs4all.nl> 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.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Appending to dictionary of lists "Alex van der Spek" <zdoor@xs4all.nl> - 2011-05-03 21:50 +0200
Re: Appending to dictionary of lists Paul Rubin <no.email@nospam.invalid> - 2011-05-03 12:56 -0700
Re: Appending to dictionary of lists "Alex van der Spek" <zdoor@xs4all.nl> - 2011-05-03 22:20 +0200
csiph-web