# Revision history [back]

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example: L1=[1,2] L2=[3,4] L1 L2 L1.extend(L2) L1 L2

output: [1, 2] [3, 4] [1, 2] [1, 2, 3, 4] [3, 4] [1, 2, 3, 4]

The same thing happens with "append". Help please!!!

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example: L1=[1,2] L2=[3,4] L1 L2 L1.extend(L2) L1 Example:

L1=[1,2]

L2=[3,4]

L1

L2

output: L1.extend(L2)

L1

L2

output:

[1, 2] 2]

[3, 4] 4]

[1, 2] 2]

[1, 2, 3, 4] 4]

[3, 4] 4]

[1, 2, 3, 4]

The same thing happens with "append". "append".

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example:

L1=[1,2]

L2=[3,4]

L3=L1

L1

L2

L3

L1.extend(L2)

L1

L2

L3

output:

[1, 2]

[3, 4]

[1, 2]

[1, 2, 3, 4]

[3, 4]

[1, 2, 3, 4]

The same thing happens with "append".

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example:

L1=[1,2]

L2=[3,4]

L3=L1

L1

L2

L3

L1.extend(L2)

L1

L2

L3

output:

[1, 2]

[3, 4]

[1, 2]

[1, 2, 3, 4]

[3, 4]

[1, 2, 3, 4]

The same thing happens with "append".

### question about defining listslists; equals sign

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example:

L1=[1,2]

L2=[3,4]

L3=L1

L1

L2

L3

L1.extend(L2)

L1

L2

L3

output:

[1, 2]

[3, 4]

[1, 2]

[1, 2, 3, 4]

[3, 4]

[1, 2, 3, 4]

The same thing happens with "append".

### question about defining lists; meaning of equals sign

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example:

L1=[1,2]

L2=[3,4]

L3=L1

L1

L2

L3

L1.extend(L2)

L1

L2

L3

output:

[1, 2]

[3, 4]

[1, 2]

[1, 2, 3, 4]

[3, 4]

[1, 2, 3, 4]

The same thing happens with "append".

Note: this does not happen with variables with numerical (not list) values. For example:

a=4

b=a

a=5

a

b

output:

5

4

So it seems that the equals sign means two different things: for numbers it is an assignment; for lists it is an identification. This is driving me crazy. I cannot find it explained anywhere (mayeb because it is so "well-known"?)

### question about defining lists; meaning of equals sign

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example:

L1=[1,2]

L2=[3,4]

L3=L1

L1

L2

L3

L1.extend(L2)

L1

L2

L3

output:

[1, 2]

[3, 4]

[1, 2]

[1, 2, 3, 4]

[3, 4]

[1, 2, 3, 4]

The same thing happens with "append".

Note: this does not happen with variables with numerical (not list) values. For example:

a=4

b=a

a=5

a

b

output:

5

4

So it seems that the equals sign means two different things: for numbers it is an assignment; for lists it is an identification. This is driving me crazy. I cannot find it explained anywhere (mayeb because it is so "well-known"?) 8 None

### question about defining Python assignment of lists; meaning of equals signsign; how to save a list?

I have a list, then modify it, but want to save the old list to then modify in a different way. I try to save the original using a different name and =, but it seems the two names are forever linked by the equals sign, so the modification also changes the original. Why does this happen, and how do I deal with this?

Example:

L1=[1,2]

L2=[3,4]

L3=L1

L1

L2

L3

L1.extend(L2)

L1

L2

L3

output:

[1, 2]

sage: L1 = [1, 2]
sage: L2 = [3, 4] [1, 2] 4]
sage: L3 = L1
sage: L1
[1, 2]
sage: L2
[3, 4]
sage: L3
[1, 2]
sage: L1.extend(L2)
sage: L1
[1, 2, 3, 4] 4]
sage: L2
[3, 4] 4]
sage: L3
[1, 2, 3, 4]4]


The same thing happens with "append".

Note: this does not happen with variables with numerical (not list) values. For example:

a=4

b=a

a=5

a

b

output:

5

4

sage: a = 4
sage: b = a
sage: a = 5
sage: a
5
sage: b
4


So it seems that the equals sign means two different things: for numbers it is an assignment; for lists it is an identification. This is driving me crazy. I cannot find it explained anywhere (mayeb (maybe because it is so "well-known"?)