Preferred Python idiom for handling non-existing dictionary keys and why?

John J. Lee jjl at pobox.com
Fri Oct 10 14:56:50 EDT 2003


Quentin Crain <czrpb at yahoo.com> writes:

> (First, I would like to mention I did try to google
> for the answer here!)
> 
> Say I am populating a dictionary with a list and
> appending. I have written it thusly:
[...]

You want the dict.setdefault method.


John




More information about the Python-list mailing list