newbe question about lists

Mike Callahan mcalla at home.com
Sat Mar 4 21:15:42 EST 2000


Fredrik S <fredrik.sjostedtNOfrSPAM at bemail.org.invalid> wrote in message
news:0d6dde44.8e4c635f at usw-ex0102-015.remarq.com...
> Sorry for this simple question, but I can't go to sleep before I
> have solved it.
>
> I am running python on Beos for the first
> time.
>
> I'm going through a study course online, and ringt now I
> am trying lists.
>
> I type the following:
> >>>
> l1=["a1","a2","a3"]
> >>> l2=["a4","a5","a6"]
> >>> l3=l1
l3 now references the same object that l1 points to. Therefore, if you
change the object the l1 points to, l3 will also change. What you want to do
is this:
>>> l3 = l1[:]
Which will create a copy of l1 and assign l3 to it.
> >>>
> l3[1:1]=l2
> >>> l3
> ['a1', 'a3', 'a4', 'a2']
Shouldn't this be ['a1', 'a4', 'a5', 'a6', 'a2', 'a3']?
> >>> l1
> ['a1', 'a3',
> 'a4', 'a2']
>
> QUESTION:
> Why is value of l1 changed... The only
> thing I can think of is B U G ...
This is a common newbe mistake. Lists are not the same as simple variables.
Get "Learning Python" and read it carefully.
>
> Can anyone help me out...
>
>
>
> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network
*
> The fastest and easiest way to search and participate in Usenet - Free!
>





More information about the Python-list mailing list