> How about the alternative approach of allowing the user to override the > action to be taken when accessing a non-existent key? > > d.defaultValue(0)
I like this a lot. It makes it more clear from the code what is going on, rather than having to figure out what the name appendlist, count, tally, whatever, is supposed to mean. When you see the value you'll know. It's more general, because you can support dictionaries and sets then as well. I think someone mentioned that it might be a problem to add another piece of state to all dicts though. I don't know enough about the internals to say anything about this. setdefault gets around this by having you pass in the value every time, so it doesn't have to store it. It's very similar, but somehow many times more awkward. -- http://mail.python.org/mailman/listinfo/python-list