Perl is worse!

Martijn Faassen m.faassen at vet.uu.nl
Fri Jul 28 23:24:45 EDT 2000


Alex Martelli <alex at magenta.com> wrote:
[snip]
> Making members into a dictionary _of lists_ seems another quite plausible
> organization, changing the loop's body to:
>     if members.has_key(name):
>         members[name].append(occ)
>     else:
>         members[name]=[occ]
> or (a matter of style):
>     try:
>         members[name].append(occ)
>     except KeyError:
>         members[name]=[occ]

I prefer (1.5.2 and later):

l = members.get(name, [])
l.append(occ)
members[name] = l 

Regards,

Martijn
-- 
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?



More information about the Python-list mailing list