The behavior of List.insert

Terry Reedy tjreedy at
Tue Apr 29 18:57:54 CEST 2003

"York" <yorklee70 at> wrote in message
news:b8m8dn$b03$1 at
> mylist = [1,2,3,4,5],
> mylist.insert(-1,99) will make mylist to be [99,1,2,3,4,5]
> just wonder why not let it to be [1,2,3,4,99,5]

Guido decided otherwise for whatever reason.  What you observed is
intended: from LibRef Mutable Sequence Types
When a negative index is passed as the first parameter to the insert()
method, the new element is prepended to the sequence. "
so this is not an implementation bug.

Terry J. Reedy

More information about the Python-list mailing list