After appending the elements from list a
into list b
, when list a
is cleared it automatically clears the elements of list a
in list b
. I don't understand how the list b[0]
is empty. Can you help me with the error in this code.
a = [1, 2, 3]
b = list()
b.append(a)
a.clear()
print(a)
print(b)
Actual output:
[]
[[]]
Expected output:
[]
[[1, 2, 3]]