inserting into a list

Diez B. Roggisch deets at nospam.web.de
Tue Mar 7 11:30:46 EST 2006


John Salerno wrote:

> Christoph Haas wrote:
> 
>> L[2:2]=[3]
> 
> I'm still a little confused about this. If what I'm inserting is just an
> integer, why wouldn't
> L[2:2] = 3
> 
> work? 

Because a slice represents a list - even if it is a one-elemented one. So,
replacing it you need another list.

> What if you wanted to insert an actual list into that slot? Would 
> you have to wrap it in double brackets?

Why don't you just _try_ that? It would have been way faster than to ask
questions you can easily answer yourself.

Diez



More information about the Python-list mailing list