Crate Stack — Lists
Six warehouse jobs, done with list operations — and the list drawn as crates so you can see what you did.
How to play
Each level names a target arrangement. Do it with list operations and press Run: your list appears as a row of numbered crates underneath the target, so an off-by-one is something you see rather than something you work out from a failure message.
Several levels check more than the answer. Level 2 insists you actually use append,
insert and a removal, because typing the finished list out by hand would teach you nothing.
What each level teaches
- Load the crates — creating a list, indexing from both ends,
len(). - Shift the stock —
append,insertandremove, which change the list in place. - Slice the shelf — the same slice syntax as strings, and the fact that slicing never changes the original.
- Sort it out —
sorted()versus.sort(),reverse=True, andkey=len. - Search the stock —
sum,max,.count(),.index()andin. - Build a new list — the accumulator pattern, collecting into a list instead of a number.
The mistake this game is built to catch
Write this and you will lose an afternoon to it:
stack = stack.append("d")
.append() changes the list and returns None, so that line throws the list away and
leaves stack set to None. The same is true of .sort(),
.insert(), .remove() and .reverse(). The rule worth memorising: if a
method changes the object, it returns None. The functions that hand you a new thing —
sorted(), reversed(), a slice — are the ones you assign.
Why level 4 checks that nothing moved
It is not pedantry. sorted(scores) gives you a new list and leaves scores alone;
scores.sort() rearranges the original and everything else pointing at it. Picking the wrong one is how
a function quietly reorders data that its caller still needed. The written version is in the
Python lists tutorial.
Frequently asked questions
What is the difference between sorted() and .sort() in Python?
sorted(items) returns a new sorted list and leaves the original untouched. items.sort() rearranges the list in place and returns None, so assigning its result gives you None rather than a sorted list.
Why does my list become None after I append to it?
Because you wrote items = items.append(x). append changes the list in place and returns None, so the assignment replaces your list with None. Write items.append(x) on its own line instead.
What is the difference between append and insert?
append(x) adds at the end. insert(i, x) puts x at position i and shifts everything after it along, so insert(0, x) adds at the front.
How do I copy a list instead of referencing it?
Use a full slice, items[:], or list(items). Plain assignment, other = items, makes both names point at the same list, so a change made through one is visible through the other.
Does this game need Python installed?
No. Your code runs on CPython compiled to WebAssembly inside the page, so every list method behaves exactly as it would on a computer.
Keep going
- Read the lists tutorial — the written explanation behind every level here.
- Variable Vault — variables & data types.
- Operator Arcade — numbers & operators.
- String Surgeon — strings & slicing.
- 20 Python practice exercises with worked solutions.
Take the games with you
Coding Python packs a real Python 3 compiler, 30 example programs, 112 quiz questions and 12 self-checking challenges into one free Android app.
Get it on Google Play