I have a list of lists, for example:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
I need to get this:
[[1, 4, 7],
[2, 5, 8],
[3, 6, 9]]
And I also need to get the diagonal. I'd preferably need to do this without importing other libraries.
I have a list of lists, for example:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
I need to get this:
[[1, 4, 7],
[2, 5, 8],
[3, 6, 9]]
And I also need to get the diagonal. I'd preferably need to do this without importing other libraries.
arr = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
[list(i) for i in zip(*arr)]
output:
[[1, 4, 7], [2, 5, 8], [3, 6, 9]]
To get the diagonal:
[arr[x][x] for x in range(len(arr))]
output:
[1, 5, 9]