I was just trying to write a code in Python for Euler Problem 15 (https://projecteuler.net/problem=15), concerning Lattice Paths.
I wanted to write something which would return (1,2,1), (1, 3, 3, 1), (1, 4, 6, 4, 1) etc. I wrote the following:
lijst = [1,1]
temp = [1,1]
for a in range(2,21):
temp.append(1)
for b in range(1,a):
temp[b] = lijst[b-1] + lijst[b]
lijst = temp
print a, lijst
To my surprise, this didn't work. At the start of the second 'for'-loop, somehow the append doesn't only work on 'temp', but also on 'lijst'. I got the code working by changing:
lijst = temp
into:
lijst = [a for a in temp]
What's the problem hear? Am I missing something out on the behaviour of lists?
Thanks!