CSC 241 Lab 8

Submission:  Submit the python or text file that contains all your answers to the submission folder for this lab by the end of the lab. To simplify Drew's (our tutor) work, please include your name and the number of the lab at the top of the file (if you're submitting a Python file, use comments: start the line with a #).

Grading: see the grading criteria for lab assignments.

1. (More loops) You want to find the longest word in a novel. Implement a function long_word(name) that finds the longest word in a file named name. We'll do this in two steps (write separate functions for each so you can go back and compare, call them long_worda, and long_wordb). You can test with innocents.txt or stranger.txt or any of the other examples we saw earlier.

a) Read the file as a string, remove punctuation using the strip(s) function shown below, and split the string into words. Then go through all the words, and find the length of the longest one, and return its length.

Use a strip() function like the following to remove punctuation from the text to get more accurate results.

Hint: since length is always positive, there is no problem with starting the maxlength at 0.

b) Return both the length of the longestword as well as the longest word itself. (Return them as a list of two elements.e.g return [maxl, mword] if maxl is the length of your longest word, and mword is that longest word.)

2. (Images) Write a function flip(iname) that takes the image named iname, and flips it along the diagonal, so rows become columns, and columns become rows (note that this also changes the height and width of the picture). For results on running flip on our test-files Eiffel.jpg and Meidner.jpg, see flip_Eiffel.jpg and flip_Meidner.jpg .

3. (2-Dimensional Lists) Write a function find(lst, item) that searches a 2-dimensional list for occurrences of item, and reports all such occurrences, by printing (for each occurrence) the position of the item in the sublist, and the position of the sublist in the list lst. Make the output look similar to the output below.

Marcus Schaefer
Last updated: May 20th, 2019.