In article <7xmy3peq3s....@ruckus.brouhaha.com>, Paul Rubin <http://phr...@nospam.invalid> wrote: >a...@pythoncraft.com (Aahz) writes: >> >> Standard Python idiom: >> >> try: >> d[key] += value >> except KeyError: >> d[key] = value >> >> Maybe you need to re-think "appropriate". > >But more recent style prefers: > > d = collections.defaultdict(int) > ... > d[key] += value
That was a trivial example; non-trivial examples not addressed by defaultdict are left as an exercise for the reader. -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --re...@lion.austin.ibm.com -- http://mail.python.org/mailman/listinfo/python-list