Errors when modifying a dictionary in python
<p>Suppose I want to create a dictionary that maps digits to numbers less than 100 ending in those digits as follows:</p>

<pre><code>d = {}
for i in range(100):
 r = i % 10
 if r in d:
  d[r] = d[r].append(i)
 else:
  d[r] = [i]
print d
</code></pre>

<p>First of all, when i is 20, d[r] is apparently a NoneType when I try to append to it, throwing an error.  Why would this be?  Secondly, I feel like my approach is inefficient, as the work in checking if r in d isn't propagated.  Something like this would be better, I feel:</p>

<pre><code>case(d[r]) of 
   SOME(L) =&gt; d[r] = L.append(i)
 | NONE =&gt; d[r] = [i]
</code></pre>

<p>Is there a way to have that logic in python?</p>
