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.
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).
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
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 a
main function to test your code at the bottom of the file. See a pattern? Every file/module will probably have a
main function from ths point on!
Append vs Extend
There are two common methods for adding elements to a list—
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 string they are called from. Read the descriptions below for more details.
Given a list
mylist and a number
n as a new entry to
append() method is said to modify
mylist in-place. This means that
append() does not return anything! Instead it directly changes
Given two lists,
mylist.extend(yourlist) adds the elements of
yourlist to the end of