The behavior of List.insert
tjreedy at udel.edu
Tue Apr 29 18:57:54 CEST 2003
"York" <yorklee70 at yahoo.com> wrote in message
news:b8m8dn$b03$1 at pegasus.csx.cam.ac.uk...
> 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 18.104.22.168 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