Skip to content
Prev 59574 / 398503 Next

How to insert one element into a vector?

Deepayan Sarkar wrote:

            
A shame then, that help.search("insert") doesn't find 'append'! I cant 
think why anyone looking for a way of _inserting_ a value in the middle 
of a vector would think of looking at "append"!

  Python has separate insert and append methods for vectors.

  >>> x=[1,2,3,4,6]
  >>> x.insert(4,5)
  >>> x
  [1, 2, 3, 4, 5, 6]
  >>> x.append(99)
  >>> x
  [1, 2, 3, 4, 5, 6, 99]


Barry