Newbie class instance tracking system
aleaxit at yahoo.com
Thu May 10 13:23:23 CEST 2001
"Lyle Johnson" <ljohnson at resgen.com> wrote in message
news:tfje5p3n0kcefa at corp.supernews.com...
> if not Maker.all_cars.has_key(carCompany):
> Maker.all_cars[carCompany] = 
Quite correct! Python 2 lets you code this in a
somewhat different manner, though:
I believe the .setdefault() method was added to
dictionaries specifically to enable this kind of
idiom for dictionaries whose values are lists
(it has other uses, of course, but this one does
look like the "typical use-case" in the design).
More information about the Python-list