Skip to content

Latest commit

 

History

History
106 lines (71 loc) · 3.88 KB

File metadata and controls

106 lines (71 loc) · 3.88 KB

Lesson 2.04: Lists

Learning Objectives

Students will be able to...

  • Define and identify: list, item, index, integer.
  • Be able to access items from a list using the index.
  • Create lists of different types.
  • Use the length function.

Materials/Preparation

Pacing Guide

Duration Description
5 Minutes Do Now
10 Minutes Lesson
35 Minutes Lab
5 Minutes Debrief

Instructor's Notes

1. Do Now

  • Students follow instructions to create lists and use the len function.

2. Lesson

Instruction

  • A list is a sequence of values. In a Python list, values can be any type. The values in a list are called elements or items.
  • In Python, to create a list you must enclose items in square brackets, and separate multiple items with commas.
  • Emphasize that you can have lists of any type (int, float, string, etc.) You can even have lists within lists (more on that later...)

Discussion

  • Ask students what len did when they used it in the Do Now.
  • Ask students how they tried to print the first item from a list. Was this what they were expecting?

More Instruction

  • index: a map from the position in the list to the element stored there.
  • 0-index: lists are 0 indexed. So the first element in the list is at an index of 0.
  • Out-of-bounds: what happened when you tried to print an element of a list, using an index value that was too large?

More Discussion

  • Ask students how they would access the last item in a list of unknown length. (Use the length function!)
  • Ask a student to write on the board how they retrieved the last element of a list. Ask another student to write how they would get the second to last element of the list and so on.

Demonstration

  • After accessing any list element you can change it. Take a moment to demonstrate this syntax before starting the lab.

Nested Lists

Have students work through the following examples in their console.

Example 1

    a_list = ['a', 'b', 'c', ['d', 'e']]
    print(len(a_list))

Example 2

    a_list = ['a', 'b', 'c', ['d', 'e']]
    b_list = a_list[3]
    print(b_list)

In their notebooks, have students explain how they would access the element d, starting from the definition of a_list.

3. Lab

  • Practice accessing and updating items in a list.
  • Implement program from last lab using lists.
  • Create a quiz program.

4. Debrief

  • Check student progress and completion of the lab. Wrap up by taking any final questions.

Accommodation/Differentiation

If students are moving quickly, you can continue the topic of nested lists. Start off with a simple nested list like ['a', 'b', 'c', [1, 2, 3]]. Ask the students to guess the length. Ask the students to guess how they would access the item '1' from that list!