Ms. Whitby's Classroom logo Ms. Whitby's Classroom

Lists & Collections — Lesson 1: Read values from a list

New skill: Lists, indexes, negative positions
Previously learned: Units 01–07

Why this matters

Scores, sensor readings, and attendance check-ins often arrive as groups of values.

Step 1 — Explore working Python

Read the program below. Before running it, write down the result you expect.

scores = [8, 12, 15]
print(scores[0])
print(scores[-1])
print(len(scores))

Step 2 — Trace the code

  1. Find the square brackets that group values into one list.
  2. Identify the first item at index 0 and the last with index -1.
  3. Use len() to count items, not the characters inside them.

Step 3 — Check your understanding

What does [5, 10, 15, 20][1] return?

Step 4 — Watch for this mistake

A list of three items has indexes 0, 1 and 2. Its last item is not at index 3.

Practice: Read values from a list

Complete end_points(values) to return a two-item list containing the first and last input items. The input always contains at least one item.

Function contract: end_points(values)
Starter file: main.py

Work in the editor, using Run to explore and Check to compare against the published examples. Your submitted code, not the public check, determines the recorded score.

Hint 1 — Start Select the value at index 0.
Hint 2 — Build Use index -1 for the final value.
Hint 3 — Test Wrap the two values in square brackets.

Reflect

In 3–5 sentences, explain the algorithm you chose, one test case you predicted, and how you would detect an incorrect answer.

Optional reading

For another perspective on this skill, see How to Think Like a Computer Scientist (interactive textbook). This Playground lesson, worked example, and exercise are original; no textbook passages were reproduced.