title: Python: understanding difference between append and extend
body: <p>The code below will not run in its current state. However, if I change <code>sum_vec.extend( vec1[i] + vec2[i] )</code> to <code>sum_vec.append( vec1[i] + vec2[i] )</code> it works just fine. I understand the basic different between append and extend, but I don't understand why the code doesn't work if I use extend. </p>
  
  <pre><code>def addVectors(v1, v2):
  
      vec1 = list(v1)
      vec2 = list(v2)
      sum_vec = []
      vec1_len = len(vec1)
      vec2_len = len(vec2)
      min_len = min( vec1_len, vec2_len )
  
      # adding up elements pointwise
      if vec1_len == 0 and vec2_len == 0:
          return sum_vec
      else:
          for i in xrange(0, min_len):
              sum_vec.extend( vec1[i] + vec2[i] )
  
      # in case one vector is longer than the other
      if vec1_len != vec2_len:
          if vec1_len &gt; vec2_len:
              sum_vec.extend( vec1[min_len : vec1_len] )
          else:
              sum_vec.extend( vec2[min_len : vec2_len] ) 
      print sum_vec
      return sum_vec
  
  v1 = [1,3,5]
  v2 = [2,4,6,8,10]
  addVectors(v1,v2)
  </code></pre>