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:
- Lists
- You should be comfortable with:
- Accessing individual characters of a list using indexing (e.g.
name[1]
) - Using the concatenation (
+
) and repetition (*
) operators on lists - Determining and using the length of a list
- Writing a loop to access each element of a list
- Accessing sublists using list slicing
- Using list support functions like
sum()
,max()
,min()
- Adding elements to a list using
append()
method and a variant of the accumulator pattern
- Accessing individual characters of a list using indexing (e.g.
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
-
- CS Circles lesson on lists
- Zelle, Sections 5.3, 11.1–11.3
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.
s = 'Seawolf Pride!' print(len(s)) print(s[len(s)-1]) print(s[8:]) print(s[-14:-5])
Exercise 2
Write what this code produces, exactly. Be very careful with whitespace and the newlines.
s = 'Go, Seawolves! Go!' s = s[:-1] + ', ' + s[:-4] print(s)
Exercise 3
Write a piece of code that produces the following input/output behavior. Text that is italics and underlined are user input.
Enter a string: lollipop There are 8 letters in lollipop: l o l l i p o pHere is a sample answer, when you think you have solved it. (Don't cheat yourself and look early).