'vertical list of matrix python

without numpy, additional library and classes (if possible). I want to make a list of vertical lines of matrix which effects the real matrix.

matrix = [[1,2,3],
          [4,5,6],
          [7,8,9]
]

vertical = [[1,4,7],
            [2,5,8],
            [3,6,9]]

vertical[0][1] = 9
print(matrix)
>>> [[1,2,3],
     [9,5,6],
     [7,8,9]]


Solution 1:[1]

I don't think that you can do it without Libraries or classes.

But, you can do something like:

matrix = [[1,2,3],[4,5,6],[7,8,9]]

v = [*map(list,zip(*matrix))] # [[1,4,7],[2,5,8],[3,6,9]]
v[0][1] = 99 # Change 4 to 99
matrix = [*map(list,zip(*v))] # Change columns and lines


print(matrix) #[[1,2,3],[99,5,6],[7,8,9]]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 TKirishima