Skip to content
Advertisement

while-loop problem for acess a list element

  • I want to append each element of [1,2] to [[1], [2], [3]] and as a consequence, the final array that I want is [[1,1], [1,2], [2,1], [2,2], [3,1], [3,2]]

    But my code has a mistake I couldn’t recognize it yet, and the result of the python code below is [[1, 1, 2], [1, 1, 2], [2, 1, 2], [2, 1, 2], [3, 1, 2], [3, 1, 2]]

The python code:

JavaScript

Advertisement

Answer

it would be eleman=arz[each].copy() as lists are mutable so every time you change an element in the original list it will get reflected in the resultant array

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement