inserting into a list

John Salerno johnjsal at NOSPAMgmail.com
Tue Mar 7 17:45:34 CET 2006


Warby wrote:
> It makes sense because a slice IS a list, so you should assign a list
> to it.  Yours is just a special case in which the target slice has a
> length of zero.  It's still a list, just an empty one:
> 
>>>> L = [1,2,4]
>>>> print L[2:2]
> []
> 
> As for your question, yes:
> 
>>>> L = [1,2,4]
>>>> L[2:2] = [[3]]
>>>> print L
> [1, 2, [3], 4]
> 
> Cheers! :)
> 

Thanks guys! What I wasn't realizing was that a slice is a list, so I 
needed a list.  :)



More information about the Python-list mailing list