Pythonic way to make sure list exists at dict key before appending
<p>I'm asking this from the perspective that my impression is that it's more Pythonic to ask forgiveness than permission.</p>

<p>So, I've got some code that's like:</p>

<pre><code>d = dict()
try:
    d[est['state']].append(est)
except Exception:
    d[est['state']] = []
    d[est['state']].append(est)
</code></pre>

<p>In the above code I ask forgiveness rather than permission at the expense of repeating myself, which is pretty lame! So, knowing no alternative, I would rather:</p>

<pre><code>d = dict()
if est['state'] in d:
    d[est['state']].append(est)
else:
    d[est['state']] = [est]
</code></pre>

<p>Both of these approach are sort of gnarly. What's a better way to do this? Best I've found so far is:</p>

<pre><code>from collections import defaultdict
d = defaultdict(list)
d[est['state']].append(est)
</code></pre>
