a = [4, 4, 4, 4] c = [] for i in range(4): b = [elem for elem in a] b[i] = 0 c.append(b) print c
Output:[[0, 4, 4, 4], [4, 0, 4, 4], [4, 4, 0, 4], [4, 4, 4, 0]]
Pheeew I managed to find a way without a module.Apparently, the list stays in memory as an element and the variables refering to the list are just pointers to it, and not a container containing a separate value we can work on without affecting the initial list.
Creating another list from the first one and modifying the second one makes it so we are not changing the original list and therefore stuff works.
It's "just" computationally inefficient.
Edit: Okay so I realize now that I could update the initial list with the X of "for x, X in enumerate(blah)" instead of pointing to the original list with all the indices like I was doing. I guess it's gonna clean up my code quite a bit.