x = y

James Lockley j_lockley at hotmail.com
Tue Feb 6 17:23:44 EST 2001


or just:

>>> x=y[:]
>>> x[1]='me'
>>> x
[[1, 2, 3], 'me']
>>> y
[[1, 2, 3], [4, 5, 6]]


cheers
james


"Bernie" <bernie at pacific.net.hk> wrote in message
news:3A807382.298371E0 at pacific.net.hk...
> "José Luis Gallego" wrote:
>
> > Hi all,
> >
> > I want to create a list x from a list y:
> >
> > y = [[1,2,3],[4,5,6]]
> > x = y
> >
> > How do I change individual elements of x without changing y?
> >
>
> I think you need the copy module.
>
> import copy
> y = [[1,2,3],[4,5,6]]
> x = copy.copy(y)
>
> This will do for a shadow copy.  See documentation for the copy module
> in Python
> Library Reference for furthur details
>
> > Thanks in advance,
> >
> > Jose Luis
>
> Bernie
>





More information about the Python-list mailing list