0

I have a list a which has some items and another list b to which I append list a. Next I want to clear list a, and repeat the process. But the problem is when I clear list a, my list b also gets clear.

for i in range(0,c)
    for j in range(0, c):
        if(x == 1):
            a.append(j)
    b.append(adj_row)
    del adj_row[:]

How do I prevent list b from getting erased when list a is cleared?

Plutonium smuggler
  • 329
  • 5
  • 6
  • 17

1 Answers1

1

A = [1,2,3,4] B = []

Copying a list in python B = A[:] Otherwise assigning list works like a pointers I mean B = A Deleting A values same as deleting B values If you do B = A[:] it will not happen

IsaBostan
  • 60
  • 4