Where is the syntax for the dict() constructor ?!

Chris Mellon arkanes at gmail.com
Thu Jul 5 18:42:41 CEST 2007

On 7/5/07, Captain Poutine <captainpoutine at gmail.com> wrote:
> I'm simply trying to read a CSV into a dictionary.
> (if it matters, it's ZIP codes and time zones, i.e.,
> 35983,CT
> 39161,CT
> 47240,EST
> Apparently the way to do this is:
> import csv
> dictZipZones = {}
> reader = csv.reader(open("some.csv", "rb"))
> for row in reader:
>      # Add the row to the dictionary
> But how to do this?
> Apparently there is no dict.append() nor dict.add()
> But what is there?  I see vague references to "the dict() constructor"
> and some examples, and news that it has been recently improved.  But
> where is the full, current documentation for the dict() constructor?

There's no dict.append or dict.add because a dict doesn't require
them. You insert keys via the normal indexing interface:

somedict[somekey] = somevalue.

Depending on which direction your mapping is, you may be interested in
the setdefault method.

The dict constructor is described in section 2.1, built in functions
(even though it's not a function anymore).

The other dict methods are described in section 3.8, mapping types.

More information about the Python-list mailing list