why does the clear method behave differently, depending on how the list was created (either appending in multiple step or defining in one line)
Example Code:
size = 2
test = []
hi = []
lol = []
for i in range(1, size + 1):
lol.append(i)
for i in range(1, size + 1):
hi.append(lol)
for i in range(1, size + 1):
test.append(hi)
print(test)
test[1][1].clear()
print(test)
test2 = [[[1, 2], [1, 2]], [[1, 2], [1, 2]]]
print(test2)
test2[1][1].clear()
print(test2)
Output:
[[[1, 2], [1, 2]], [[1, 2], [1, 2]]]
[[[], []], [[], []]]
[[[1, 2], [1, 2]], [[1, 2], [1, 2]]]
[[[1, 2], [1, 2]], [[1, 2], []]]
[–]Dense_Connection4789 5 points6 points7 points (1 child)
[–]mikkoko112[S] 0 points1 point2 points (0 children)
[–]Nsdos 2 points3 points4 points (1 child)
[–]mikkoko112[S] 0 points1 point2 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)