Answer to Question #173937 in Python for phani

Question #173937
Elements of Anti Diagonal
Write a program to print the anti-diagonal elements in the given matrix.
Input
The first line of input will contain an integer N, denoting the number of rows and columns of the input matrix.
The next N following lines will contain N space-separated integers, denoting the elements of each row of the matrix.
Output
The output should be a list containing the anti-diagonal elements.
Explanation
For example, if the given N is 3, and the given matrix is
1 2 3
4 5 6
7 8 9
The anti diagonal elements of the above matrix are 3, 5, 7. So the output should be the list
[3, 5, 7]
Sample Input 1
3
1 2 3
4 5 6
7 8 9
Sample Output 1
[3, 5, 7]
Sample Input 2
5
44 71 46 2 15
97 21 41 69 18
78 62 77 46 63
16 92 86 21 52
71 90 86 17 96
Sample Output 2
[15, 69, 77, 92, 71]
1
Expert's answer
2021-03-22T07:59:29-0400
n = int(input())
a = []
for i in range(n):
    b = list(map(int, input().split()))
    a.append(b[n - 1 - i])
            
print(a)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS