0

I need A to be a copy of C How can I copy nested lists?

Attempt:

b = [["1","1","1"],["1","1","1"],["1","1","1"]]
c = [["2","2","2"],["2","2","2"],["2","2","2"]]
a = c.copy()

Result:

'list' object has no attribute 'copy' 

a = c does not work

Attempt:

b = [["1","1","1"],["1","1","1"],["1","1","1"]]
c = [["2","2","2"],["2","2","2"],["2","2","2"]]
a = c
for y in range(0,3):
  for x in range(0,3):
    c[x][y] = b[2-x][2-y]
print(a)

Result:

[['1', '1', '1'], ['1', '1', '1'], ['1', '1', '1']]
  • What version of python are you using? – juanpa.arrivillaga Dec 11 '22 at 19:52
  • 1
    Side-note: `list` has a `copy` method in modern Python (though it only shallow copies, so it's not enough by itself for what you want). Are you inadvertently using an ancient version, in the Python 2.x line? If so, stop what you're doing, right now, and switch to Python 3; Python 2 has been end-of-life for over two years, and learning it will handicap you. – ShadowRanger Dec 11 '22 at 19:52

0 Answers0