In article <[email protected]>, Paul Rubin <http://[email protected]> wrote: >[email protected] (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 ([email protected]) <*> 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." [email protected] -- http://mail.python.org/mailman/listinfo/python-list
