> I simply fail to understand the semantics of the following piece of
code.
> #assuming ls=[1,2,3,4]
> >>>ls[1:1]=[5,6]
> #then ls becomes
> >>> ls
> [1, 5, 6, 2, 3, 4]
> Basically, ls[1:1] returns an empty list and assigning [5,6] to
> it, actually inserts the elements... but how?
ls[1:1] re
> (For the gory details on what is allowed on the right hand side of an
^
> assignment, you can take a quick look at the Reference Manual:
Hi Venkata,
Gaaa, I don't know my left from my right. *grin* I meant to say "left"
hand side, since
On Fri, 3 Jun 2005, venkata subramanian wrote:
> I am a newbie to Python (that's very guessable).
> I simply fail to understand the semantics of the following piece of code.
> #assuming ls=[1,2,3,4]
> >>>ls[1:1]=[5,6]
> #then ls becomes
> >>> ls
> [1, 5, 6, 2, 3, 4]
>
> i would be hap
when you operate slice be carefull of the position of pointer which
slice the list:
L = [0 , 1 , 2 , 3]
^ ^
pos 0 1
That's why :
L = [1,2,3]
L[0:1] = [7]
print L # will replace element 1
L = [1,2,3]
L[1:1] = [7]
print L # will insert 7 between element 1 and 2
Hi,
I am a newbie to Python (that's very guessable).
I simply fail to understand the semantics of the following piece of code.
#assuming ls=[1,2,3,4]
>>>ls[1:1]=[5,6]
#then ls becomes
>>> ls
[1, 5, 6, 2, 3, 4]
i would be happy to know how it works.
Basically, ls[1:1] returns an empty