inserting into a list

John Salerno johnjsal at NOSPAMgmail.com
Tue Mar 7 17:01:18 CET 2006


Diez B. Roggisch wrote:

>>>> l = [1,2,3]
>>>> l.insert(2, 10)
>>>> l
> [1, 2, 10, 3]
> 
> Embarrasing enough?

Actually, I was trying to figure it out with the slice technique 
instead. But yeah, as Christopher's example showed, it's not hard. But I 
didn't realize you had to assign a list item to the slice, so I was doing:

L[2:2] = 3

among other things, but they all involved '= 3', not '= [3]'



More information about the Python-list mailing list