Learning Objectives

Through readings, lecture and labs, it is expected that you are doing work and seeking help to keep pace with the below objectives:

Functions

You shoud be achieving much greater competance with this topic's objectives from last week.

Lists of Lists
Over the next two weeks, you should be comfortable with:
  • Reasoning about strings inside lists
  • Reasoning about lists inside lists (2D lists)
  • Using indexing to in both cases
  • Determining the lengths and looping over these structures

Required Reading


Supplemental Materials

We all need alternative presentations of the concepts from time to time. The following resources are optional. If something seems unclear after class, or the pratice questions seem hard for you, then explore these topics more using the resources below.

Lists of Lists

Practice

For all these exercises, I recommend you try them on paper and then test them out with PythonTutor.

Exercise 1

Write what this code produces, exactly. Be very careful with whitespace and the newlines.

def f(x, y):
    return x*2 + y

d = "dog"
c = "cat"
print(f(d, c), f(len(d), len(c)))

Exercise 2

Write a function called count_long_words that conforms to the below docstring.

'''Counts the number of words in a string that are more than a certain length.

Args:
    s (str): A string
    n (int): The size of the smallest word to count

Returns:
    int: the number of words that are n or greater in length
'''
Here is a sample answer, when you think you have solved it. (Don't cheat yourself and look early).

Exercise 3

Write a set of nested loops that produces a 2D list filled with all zeros, of dimension 5 by 10. As a reminder, a 2D list filled with all zeros of dimension 2 by 3 looks like: [ [0,0,0], [0,0,0] ]

Here is a sample answer, when you think you have solved it. (Don't cheat yourself and look early).