Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #4571

Re: Appending to dictionary of lists

Path csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.octanews.net!indigo.octanews.net!auth.brown.octanews.com.POSTED!not-for-mail
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 Tue, 03 May 2011 12:56:44 -0700
Message-ID <7x7ha75zib.fsf@ruckus.brouhaha.com> (permalink)
Organization Nightsong/Fort GNOX
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)
Cancel-Lock sha1:pzrhMxhIDTo+YlRAtmNJJQD2Ncw=
MIME-Version 1.0
Content-Type text/plain; charset=us-ascii
Lines 9
NNTP-Posting-Date 03 May 2011 14:56:44 CDT
X-Complaints-To abuse@octanews.net
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:4571

Show key headers only | View raw


"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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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