title: Add values to dict of list in Python?
body: <p>I have this kind of dictionary of lists, initially empty:</p>
  
  <pre><code>d = dict()
  </code></pre>
  
  <p>Now the use case is to simply add a value to list under a key, which might be a new or an existing key. I think we have to do it like this:</p>
  
  <pre><code>if key not in d:
      d[key] = list()
  d[key].append(value)
  </code></pre>
  
  <p>This seems awfully tedious and error-prone, needing to write multiple lines (with copy-paste or helper function). Is there a more convenient way?</p>
  
  <p>If there isn't "only one way to do it", and you <em>know</em> it, you can also answer that, and maybe suggest alternative ways to accomplish above, even if they aren't necessarily better.</p>
  
  <p>I looked for duplicate, didn't find, but perhaps I just didn't know to use right keywords.</p>