Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeder.erje.net!news.mixmin.net!.POSTED.2a01:4f8:100:5243::4!not-for-mail From: Steve Crook Newsgroups: comp.lang.python Subject: Dictionaries and incrementing keys Date: Tue, 14 Jun 2011 10:57:44 +0000 (UTC) Organization: Mixmin Message-ID: Injection-Date: Tue, 14 Jun 2011 10:57:44 +0000 (UTC) Injection-Info: news.mixmin.net; posting-host="2a01:4f8:100:5243::4"; logging-data="26253"; mail-complaints-to="abuse@mixmin.net" User-Agent: slrn/pre1.0.0-26 (Linux) Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:7600 Hi all, I've always done key creation/incrementation using: if key in dict: dict[key] += 1 else: dict[key] = 1 Today I spotted an alternative: dict[key] = dict.get(key, 0) + 1 Whilst certainly more compact, I'd be interested in views on how pythonesque this method is.