dictionary wart

Jesper jolsen at mail2world.com
Thu Mar 18 14:46:19 CET 2004

Paul Rubin wrote:
> jolsen at mail2world.com (Jesper Olsen) writes:
>>Does python have a way of defining a dictionary default? 
>>I think not, but are there any plans to incorporate it?
>>Intuitively I would imagine that
>>would do this -ie. a[my_new_key] should now return the the default
>>value my_default instead of creating an exception. 
> No, instead of a[my_new_key] use a.get(my_new_key, my_default).
> That does what you want.

Unfortunately not - get() is different, because you can not assign to it.
For instance in a dictionary which is mapping strings to integers (or 
lists), I would like to do


expressing that with get() would be awkward.


More information about the Python-list mailing list