list.insert question

Brian Kelley bkelley at
Wed Jan 8 22:33:50 CET 2003

So I was playing with list.insert and expected

l.insert(-2, 5)

to become
l = [1,2,3,5,4]

This is mainly because the slice "wraps" (nicely) around to the end of 
the list.

I checked the manaul and indeed:

(4) When a negative index is passed as the first parameter to the 
insert() method, the new element is prepended to the sequence.

I was wondering why this was the case.  Is there really a dichotomy 
between slices and inserts?  Is this something that will trip up a 
novice or is this geared toward 


More information about the Python-list mailing list