Help with Dictionaries and Classes requested please.

Sion Arrowsmith siona at
Thu Aug 9 17:51:01 CEST 2007

special_dragonfly <Dominic at> wrote:
>        if key in FieldsDictionary:
>            FieldsDictionary[key].append(FieldClass(*line.split(",")))
>        else:
>            FieldsDictionary[key]=[FieldClass(*line.split(","))]

These four lines can be replaced by:

FieldsDictionary.setdefault(key, []).append(FieldClass(*line.split(",")))

\S -- siona at --
   "Frankly I have no feelings towards penguins one way or the other"
        -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump

More information about the Python-list mailing list