title: Python: Removing elements from list that is a value in a dictionary?
body: <p>I have the following dictionary:</p>
  
  <p><code>a = dict()</code></p>
  
  <p><code>a["A"] = [1,2,3,4,5]</code></p>
  
  <p><code>a["B"] = [1,2]</code></p>
  
  <p>I want to iterate through each value (in this case in the form of a list) in the dictionary and if the number of elements in the list is greater than 2, I want to remove all the elements after the second element.</p>
  
  <p>For example, after I alter the values, my dictionary should be:</p>
  
  <p><code>a["A"] = [1,2] # [3,4,5] are removed from this value</code></p>
  
  <p><code>a["B"] = [1,2]</code></p>
  
  <p>I tried:</p>
  
  <p><code>del a["A"][3:len(a[2])]</code></p>
  
  <p>But this returned:</p>
  
  <p><code>[3, 4, [1, 2, 3]]</code></p>
  
  <p>Two questions:
  1) Why is the output of my attempt the way it is?
  2) How would I correctly implement what I am trying to do?</p>
  
  <p>Thanks!</p>