The behavior of List.insert

Tim Peters tim.one at comcast.net
Tue Apr 29 12:29:57 EDT 2003


[York]
> given
>
> 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]

If you read the docs, you'll see that this is the documented behavior, in
Python 2.2.2 and earlier.

However, that behavior has changed in Python 2.3:

Python 2.3b1 (#40, Apr 25 2003, 10:15:10) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> mylist = [1, 2, 3, 4, 5]
>>> mylist.insert(-1, 99)
>>> mylist
[1, 2, 3, 4, 99, 5]
>>>






More information about the Python-list mailing list