Duplicated List...

Fran=?ISO-8859-1?B?5w==?=ois Granger fgranger at teleprosoft.com
Tue Dec 26 05:05:06 EST 2000


in article 929lq7$ds1$1 at hiline.shinbiro.com, dyo at dyo at shinbiro.com wrote
on 26/12/00 9:54:

> Hi everyone.
> 
>>>> a=[1,2,3]
>>>> b=[a,10,20,30]
>>>> b[0].append('x')
>>>> b
> [[1, 2, 3, 1, 2, 3, 'x'], 10, 20, 30]
>>>> a
> [1, 2, 3, 1, 2, 3, 'x']
>>>> a.append('xxx')
>>>> a
> [1, 2, 3, 1, 2, 3, 'x', 'xxx']
>>>> b
> [[1, 2, 3, 1, 2, 3, 'x', 'xxx'], 10, 20, 30]
> 
> Duplicated List work above..
> 
> 
> But in this case..
> 
>>>> a=[1,1000]
>>>> a
> [1, 1000]
>>>> b
> [[1, 2, 3, 1, 2, 3, 'x', 'xxx'], 10, 20, 30]
>>>> 
> 
> Why do not change List 'b' ?
> What happen List 'b' ?

a is a reference to the list. You then make a e reference to another list.

I guess that if you do
a[:] = [1,1000]
it may work ?

Salutations,
Francois Granger
-- 
fgranger at teleprosoft.com - <http://www.teleprosoft.com>
tel: +33 1 41 88 48 00 - Fax: + 33 1 41 88 04 90




More information about the Python-list mailing list