Raymond Hettinger wrote: > The rationale is to replace the awkward and slow existing idioms for > dictionary based accumulation: > > d[key] = d.get(key, 0) + qty > d.setdefault(key, []).extend(values) >
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) and the accumulation becomes: d[key] += 1 and: d.defaultValue(function=list) would allow a safe: d[key].extend(values) -- http://mail.python.org/mailman/listinfo/python-list