inserting into a list
Mel Wilson
mwilson-to at sympatico.ca
Tue Mar 7 11:24:21 EST 2006
John Salerno wrote:
> Christoph Haas wrote:
>> L[2:2]=[3]
[ ... ]
What if you wanted to insert an actual list into that
slot? Would
> you have to wrap it in double brackets?
Yep.
It's a strong-typing thing. Slices of lists are lists, and
therefore what you assign to one has got to be a list, or
convertible to a list (a tuple would work.)
Python 2.4.2 (#1, Jan 23 2006, 21:24:54)
[GCC 3.3.4] on linux2
Type "help", "copyright", "credits" or "license" for more
information.
>>> a=[1,3,4]
>>> a[2:3]
[4]
>>> a[2:2]
[]
>>> a[1:1]=[2]
>>> a
[1, 2, 3, 4]
>>> a[1:2]
[2]
Mel.
More information about the Python-list
mailing list