I have a list
called ones
that changes value after a block of code that shouldn't affect it. Why?
s = 3
ones = []
terms = []
for i in range (0, s):
ones.append(1)
terms.append(ones)
print(terms)
twos = []
if len(ones) > 1:
twos.append(ones)
twos[-1].pop()
twos[-1][-1] = 2
print(twos)
print(terms)
Output:
[[1, 1, 1]] # terms
[[1, 1, 2]] # twos
[1, 1, 2] # terms
For context, I'm trying to use this to begin to solve the problem on page 5 of this British Informatics Olympiad past exam: http://www.olympiad.org.uk/papers/2009/bio/bio09-exam.pdf.