# 9. 2D Lists

• Feel free to use your laptop

• You are strongly encourage to work with others

• When you get stuck, ask those sitting around you for help

• Get used to working together in the labs

• Peer teaching and peer learning has been empirically shown to be very effective

## 9.1. Pre Lab Exercises

• For all exercises

• Do not make a `vector.py` file, just use Colab like you have been

• Use `assert` to test instead of their `test` function

1. Chapter 11 exercise(s)

• 7

• 8

2. Write assertion tests for each of your functions above

## 9.2. Before Kattis

Note

Although the below example is a 3x3 matrix (list of lists), your functions should work on any sized matrix. For example, 4x4, 5x23, 230x19973.

In other words, the following is not correct as it will only ever work for a 3x3 matrix.

```def printRow(mat, row):
print(mat[row])
print(mat[row])
print(mat[row])
```

Given the following code:

```twoD = [['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i']]
```
1. Write a function `print_row(matrix, row: int):`

• `matrix` is a list of lists (2D list)

• `row` is the specified row to print

• The function will print out the values from the specified row

• Each value can be on its own line

• The function will not return anything

• Verify correctness by running the function on multiple 2D lists 2. Write a function `print_column(matrix, column: int):`

• `matrix` is a list of lists (2D list)

• `column` is the specified column to print

• The function will print out the values from the specified column

• Each value can be on its own line

• The function will not return anything

• Verify correctness by running the function on multiple 2D lists 3. Write a function `print_down_right(matrix):`

• `matrix` is a list of lists (2D list)

• The function will print out the values of the matrix diagonal starting in the top left moving down to the right

• Each value can be on its own line

• The function will not return anything

• Verify correctness by running the function on multiple 2D lists 4. Write a function `print_up_right(matrix):`

• `matrix` is a list of lists (2D list)

• The function will print out the values of the matrix diagonal starting in the bottom left moving up to the right

• Each value can be on its own line

• The function will not return anything

• Verify correctness by running the function on multiple 2D lists 5. Write a function `print_down_left(matrix):`

• `matrix` is a list of lists (2D list)

• The function will print out the values of the matrix diagonal starting in the top right moving down to the left

• Each value can be on its own line

• The function will not return anything

• Verify correctness by running the function on multiple 2D lists 6. Write a function `print_up_left(matrix):`

• `matrix` is a list of lists (2D list)

• The function will print out the values of the matrix diagonal starting in the bottom right moving up to the left

• Each value can be on its own line

• The function will not return anything

• Verify correctness by running the function on multiple 2D lists 7. To verify that your functions work on arbitrary sized 2D lists, what happens if you run your functions with the following matrix?

• Ensure each function works as expected

• If the functions are only printing out three values, there is something wrong

```fourXfour = [['a', 'b', 'c', 'w'],
['d', 'e', 'f', 'x'],
['g', 'h', 'i', 'y'],
['j', 'k', 'l', 'z']]
```

## 9.3. Kattis Problems

• You should be using a scrap piece of paper to work out the ideas for the following problems

• The problems you are to solve are getting too complex to try to solve by just coding

• Trying to solve problems by just typing away will not yield success