title: Appending values to a dictionary in Python
body: <p>I'm looking at the smartest way of using a dictionary to handle some data output. I have a unique key which will have associated it other values so for example we have 1:[2, 3, 4, 7], 2:[8, 9, 5]. What I'd like to do is to be able to append the values such that the for the first key I could add the number 13 and get the following:</p>
  
  <pre><code>1:[2, 3, 4, 7, 13], 2:[8, 9, 5]
  </code></pre>
  
  <p>Append does not seem the smartest way of doing this. I am using:</p>
  
  <pre><code>dict[master = dict[master].append(id)
  </code></pre>
  
  <p>but I get the following:</p>
  
  <p>AttributeError: 'int' object has no attribute 'append'</p>
  
  <p>Now I could simply take the previous values of they key and simply do the following (id = 17):</p>
  
  <blockquote>
    <p>newvalue = values, id</p>
  </blockquote>
  
  <p>but this would lead to extra brackets such as</p>
  
  <pre><code>1:[[2, 3, 4, 7, 13], 17] 
  </code></pre>
  
  <p>What is the smartest way of ensuring that I only get numbers in one set of brackets i.e.</p>
  
  <pre><code>1:[2, 3, 4, 7, 13, 17] 
  </code></pre>
  
  <p>I could use some stripping functions - but is there a good easy way and simple way of doing this. I might be overlooking something simple here. Thanks in advance.</p>