[Tutor] Fwd: list method help

Rinzwind w.damen at gmail.com
Fri Feb 3 14:30:07 CET 2006


Chris or Leslie Smith: sorry wrong addess :*(


This bit l[:]=l[-1:]+l[0:-1] I think is VERY elegant. When I saw this
in your post I tought: DUH.
I did the same with 1 line more but I am still new to python ;)

Regarding the rest of the 'aside'.

What is the reasoning behind this:

###
>>> l=range(3)
>>> a=l     # 'a' is pointing at what 'l' is pointing at
>>> l[0]=42 # I make a change to the thing that 'l' points to
>>> print a
[42, 1, 2]
>>> print l
[42, 1, 2]
>>>
###

-Why- are these 2 bound together? Is there a specific reasoning behind it?

Cuz in Basic (if we had lists............) I'd expect this:

###
>>> l=range(3)
>>> a=l     # 'a' is pointing at what 'l' is pointing at
>>> l[0]=42 # I make a change to the thing that 'l' points to
>>> print a
[0, 1, 2]
>>> print l
[42, 1, 2]
>>>
###

To get there you'd need 1 more line:

What is the reasoning behind this:

###
>>> l=range(3)
>>> a=l     # 'a' is pointing at what 'l' is pointing at
>>> l[0]=42 # I make a change to the thing that 'l' points to
>>> a=l  <------- this one added by ME.
>>> print a
[42, 1, 2]
>>> print l
[42, 1, 2]
>>>
###


Oh and I DO think it's a cool feature btw. But I had me guessing alot too.


More information about the Tutor mailing list