Why does append overwrite the list?
问题 I was trying some questions from hackerrank and came across this question https://www.hackerrank.com/challenges/list-comprehensions/problem I tried this solution if __name__ == '__main__': x = int(input()) y = int(input()) z = int(input()) n = int(input()) L = [] SL = [] for i in range(0, x + 1): for j in range(0, y + 1): for k in range(0, z + 1): if i + j + k != n: SL[:] = [] SL.append(i) SL.append(j) SL.append(k) print(SL) L.append(SL) print(L) although SL had the right solution I can't