Newbie lists question

Robert Amesz reqhye72zux at mailexpire.com
Mon Aug 13 22:29:14 EDT 2001


Wolfe Maykut wrote:

>     if prefixes.has_key(prefix): 
>        prefixes[prefix].append(file)
>     else:
>         prefixes[prefix] = []
>         prefixes[prefix].append(file)
>
> Is there a nicer way of doing this that I'm missing?

How about:

   prefixes.setdefault(prefix, []).append(file)



HTH,
Robert Amesz



More information about the Python-list mailing list