Skip to content

Change the list

A list is alive: points get added during a game, products land in a basket, rankings shift. A list has its own methods — operations you call with a dot.

Inputs (for input())

One value per line — read in order by input().

Output
 
  • .append(x) — adds to the end
  • .remove(x) — removes the first x it finds
Inputs (for input())

One value per line — read in order by input().

Output
 

.sort() arranges numbers from smallest to largest, and text in alphabetical order.

in checks whether an item is in the list — the result is True/False, so it plugs straight into an if:

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Fill the basket

+10 XP

Add cheese and eggs to the basket (with .append()) and print the final list.

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Tournament table

+15 XP

Sort the scores from smallest to largest and print the list.

Inputs (for input())

One value per line — read in order by input().

Output
 
Mission

Guest list

+15 XP

You’re the party’s doorkeeper: if the name is on the list, let them in; if not, decline politely. (The inputs include Nigar.)

Inputs (for input())

One value per line — read in order by input().

Output
 

Next lesson: a list keeps things in order — but what if you need a name → value match? Dictionaries (dict) are next. Continue →