To iterate over a Two-Dimensional List in Python, you can use nested for loops, with an outer loop iterating over rows and an inner loop iterating over columns. The outer loop iterates over each row of the 2D list, while the inner loop iterates over each element in the current row.
In this example,
matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
for row in matrix:
for element in row:
print(element, end=' ')
print()
1 2 3 4 5 6 7 8 9
In this example,
matrix = [['apple', 'banana'], ['cherry', 'orange']]
for row in matrix:
for element in row:
print(element, end=' ')
print()
apple banana cherry orange
In this tutorial, we learned How to Iterate over a Two Dimensional List in Python language with well detailed examples.