I am looking to randomly generate a list and change one element in the list to create a new list. Whilst keeping track of all the generated lists.
For example:
values_possible = [0,0.5,1]
combinations = []
combinations.append([random.choice(values_possible) for i in range(8)])
lets say this generates
[0,0.5,0.5,0,0.5,0.5,1.0,1.0]
then if I copy this list and change one element, say combinations[1][1]
# set a new list to equal the first and then change one element
combinations.append(combinations[0])
combinations[1][1] = 0.33
print(combinations[0])
print(combinations[1])
this returns
[0,0.33,0.5,0,0.5,0.5,1.0,1.0]
[0,0.33,0.5,0,0.5,0.5,1.0,1.0]
it seems both combinations[0][1] and combinations[1][1] have changed to 0.33. Is there a way to solve this? May I ask why this happens and what I am misunderstanding about lists? I had expected the following output:
[0,0.5,0.5,0,0.5,0.5,1.0,1.0]
[0,0.33,0.5,0,0.5,0.5,1.0,1.0]