Duplicating a variable
hnessenospam at yahoo.com
hnessenospam at yahoo.com
Thu Jan 24 12:43:17 EST 2008
On Jan 24, 9:36 am, "hnessenos... at yahoo.com" <hnessenos... at yahoo.com>
wrote:
> I have run into a bit of a subtle problem. How do I go about
> duplicating a variable (particularly a list of lists) in python. I
> was surprised when simple assignment didn't work. For example, let y =
> [1,2,3]
>
> >>> x = y
> >>> x[2] = 5
> >>> y
>
> [1,2,5]
>
> It seems that simply assigning x to y allows further modification of y
> via x. (I'm new to python and I'm sure this is obvious to experienced
> users). So my question, how do I go about duplicating a variable
> which I can then manipulate independently?
>
> Thanks,
>
> -Hans
Ah, found the copy module... Much better. Thanks,
-Hans
More information about the Python-list
mailing list