Warmup

Part A: String Editor

In stringedit.py, you will find a few functions that could be helpful if you wanted to do fun things with strings. Whoever wrote them even documented them well, with an example input and desired output! However, none of the functions are implemented correctly; each one has a bug that causes it to break. For each of the functions, do the following with your partner and write your answers in WARMUP.md.

  1. Look at the code without running it, and try to guess what the code will actually do on the given test case.
  2. Run the code on the test case, and try to figure out what mistake the programmer made. Can you figure out what they were thinking?
  3. Figure out how to correctly implement the function and fix it (make sure to test your solution).

For step 2, you should test your functions by adding code to the main function at the bottom of your stringedit.py (below the function definitions).

Reminder

After you complete this function and add your notes to WARMUP.md be sure to commit and push your changes!

Reminder

After you complete this function and add your notes to WARMUP.md be sure to commit and push your changes!

Part B: 2D List Editor

One way to think about a list of lists is as a table. In particular, if you have a list of m inner lists, each of length n, this is like a table with m rows and n columns. Each of the inner lists is a row. For example: [[1,2,3,4],[5,6,7,8],[9,10,11,12]] can be thought of like this:

1  2  3  4

5  6  7  8

9 10 11 12

In tableedit.py, you will find a few functions that manipulate 2D lists of numbers by editing their entries or gluing them together. Again, the functions are broken. Throughout the code in tableedit.py, assume that all 2D lists given as input have the same number of rows as columns. For each function, again do steps 1-3 from the previous part, with your partner. There is also space to test your code at the bottom of the file.

Reminder

After you complete this function and add your notes to WARMUP.md be sure to commit and push your changes!

Append vs Extend

There are two common methods for adding elements to a list—append() and extend(). These methods are similar, but they are not identical. append() adds a single new entry to a list; whereas extend() adds all of the elements of one list onto the end of another list. That said, both methods directly modify the list they are called from. Read the descriptions below for more details.

.append():

Given a list mylist and a number n, mylist.append(n) adds n as a new entry to mylist. The append() method is said to modify mylist in-place. This means that append() does not return anything! Instead it directly changes mylist.

.extend():

Given two lists, mylist and yourlist, mylist.extend(yourlist) adds the elements of yourlist to the end of mylist. Again, extend() modifies mylist in-place.