It's been a while since I used Python, And this one I really don't get: - I make a list of strings M1 - I copy it to M2 - Then I change a "e" to "E" using re.sub in M1 - M2 is also changed!
Here's is some code for thos who are interested. It shows this behaviour on both Anaconda2 and Python 3.6.0.
import re
# Normal operation on single strings
m1 = "Hello."
m2 = m1
m1 = re.sub("e", "E", m1)
print(m1)
print(m2)
print("")
# Normal operation on one list of strings
M = ["Hello.", "Bye-bye!"]
for i in range(len(M)):
M[i] = re.sub("e", "E", M[i])
print (M)
print("")
# Unexpected behaviour on a copied list of strings
M1 = ["Hello.", "Bye-bye!"]
M2 = M1
for i in range(len(M1)):
M1[i] = re.sub("e", "E", M1[i])
print(M1)
print(M2)