CurriculumPython Lists, Indexing and Slicing for KidsThe Grand Inventory Check
Practice Challenge: Sorting a Python List by Hand
Lists, loops, and decisions — sorting a whole hoard, one item at a time.
The Grand Inventory Check
You know indexing, slicing, append, remove, and shared references. Now put a loop and a decision on top.
for item in a_list: visits every item — same pattern you've already used with whileloops' patrol.
values = [50, 200, 10]
for v in values:
print(v)Output
50
200
10Add an if/elif/else inside that loop, and you can react DIFFERENTLY to each item, all in one pass through the list.
Check your understanding
values = [50, 200, 10]. Using if/elif/else with 150 and 20 as cutoffs, how many lines print?
Why: Three values, three passes, one label each — the loop and the conditional work together exactly like they did in the whileloops boss, just walking a list instead of counting with range().
What you'll practice
party = ["Ember", "Blaze", "Frost"]. Loop over the party and print a greeting for each name — using for name in party:, not indexing.
More from this topic
The Grand Inventory Check is one lesson inside Python Lists, Indexing and Slicing for Kids — see the full lesson order and what the whole topic covers.
View the full topic →