On Jan 24, 9:55 am, [EMAIL PROTECTED] wrote:
>
> If your variable contains a list, then you can copy it like this:
>
> >>> l1 = [1, 2, 3]
> >>> l2 = l1[:]
> >>> l2[1] = 4
>
> As you can see now they are two distinct lists:
>
> >>> l1
> [1, 2, 3]
> >>> l2
>
> [1, 4, 3]
>
> If you want to copy any ki
Hans:
> 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.
Python is quite high-level language, but now and then it too accepts
some compromises t
[EMAIL PROTECTED] a écrit :
> 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.
using the deepcopy function of the copy module.
> I
> was surprised when simple assignment didn't work. For example,
ne, '5c', ['6a', '6b', '6c']], 7, 8]
>>> a
[1, 2, 3, 4, ['5a', None, '5c', ['6a', '6b', '6c']], 7, 8]
>>> a[4][1] = "Something"
>>> a
[1, 2, 3, 4, ['5a',
On Jan 24, 9:36 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
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, l
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 tha