Help with Dictionaries and Classes requested please.

Sion Arrowsmith siona at chiark.greenend.org.uk
Thu Aug 9 17:51:01 CEST 2007


special_dragonfly <Dominic at PLEASEASK.co.uk> 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 chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
   "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