5. Nested Lists. In Python, you can create nested lists, which are lists within lists. Nested lists are useful for representing structured data, such as matrices or tables.
For example, you can create a nested list to represent a 2x2 matrix: matrix = [[1, 2], [3, 4]]
.
To access elements in nested lists, you must specify two indices (e.g. matrix[0][1]
).
In the exercise below, a matrix has been defined for you. Access the element in the first row and second column.