Question: Consider the following Python statement, which creates a two-dimensional list of integers: USE LOOPS twoD = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Consider the following Python statement, which creates a two-dimensional list of integers: USE LOOPS
twoD = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Write a code fragment that uses one or more loops to print the values in the anti-diagonal of the list to which twoD refers i.e., the values along a diagonal line from the bottom-left corner to the upper-right corner. Print each value on its own line.
For the list above, the following values would be printed:
7 5 3
Your code should be general enough to work on any two-dimensional list in which the dimensions are equal i.e., the number of rows is the same as the number of columns.
Hint: To determine the necessary pattern, make a table showing the row and column indices of each element in the anti-diagonal. What is true about each pair of indices?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
