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.
Add, remove
Section titled “Add, remove”Inputs (for input())
One value per line — read in order by input().
.append(x)— adds to the end.remove(x)— removes the firstxit finds
Inputs (for input())
One value per line — read in order by input().
.sort() arranges numbers from smallest to largest, and text in alphabetical order.
in — “is it inside?”
Section titled “in — “is it inside?””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().
Missions
Section titled “Missions”Fill the basket
+10 XP ✓ CompletedAdd 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().
Tournament table
+15 XP ✓ CompletedSort the scores from smallest to largest and print the list.
Inputs (for input())
One value per line — read in order by input().
Guest list
+15 XP ✓ CompletedYou’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().
Next lesson: a list keeps things in order — but what if you need a name → value match? Dictionaries (dict) are next. Continue →