inserting into a list

Warby Mark.Warburton at gmail.com
Tue Mar 7 11:41:49 EST 2006


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! :)




More information about the Python-list mailing list