Case File: The Sign-Up Sheet
A first-aid course sign-up sheet was typed by hand: blank lines, spaces, the same name in capitals and in lower case, and the same name twice. Clean it with a loop and a set so that each person appears once with the spelling they typed first, sort the names ignoring capitals, and count what was thrown away. Learn lists, strings, sets and sorting by doing a real job. The sheet is generated for you alone.
Sabi Logistics · Python 2
The Sign-Up Sheet
Forty people signed up and the room holds thirty-two, but nobody knows how many different people there are
Emeka Support engineer · Phone call
Emeka. We have a sign-up sheet for the first-aid course. The room holds thirty-two and the sheet has forty lines, but people typed their own names, so there are blank lines, names with spaces in front, ADA and Ada and ada, and some people signed twice.
I need the real list: each person once, in the order that they signed, written as they first typed it, and then the same list in alphabetical order. And tell me how many lines you threw away, so that I can check your number against mine.
The brief
What you need to know first.
- Strings are text.
text.strip()removes the spaces at both ends,text.lower()makes it lower case, andtext == ""tests for empty. A string that only has spaces is empty afterstrip(). - A set remembers.
seen = set()starts an empty set;seen.add(key)puts a value in;key in seenanswers “have I met this before?” at once. A set is the tool for “each only once”. The usual pattern: for each item, make its key (the lower-case stripped text),continue(skip to the next item) if the key is inseen, otherwise add it and keep the item. - The order and the first spelling. Keep the kept names in a list with
cleaned.append(text); because you append as you go, the list is in the order of first appearance, and the spelling kept is the first one that was seen. - Sorting.
sorted(names)puts capital letters before small ones, which is not what a person expects.sorted(names, key=lambda t: t.lower())sorts by the lower-case version, ignoring capitals.lambda t: ...is a tiny function written in one line. - Fill in
clean(req)returning{"cleaned", "sorted_names", "removed"}, then the three variables. The checks runcleanon sheets that you cannot see: one name in three spellings, and a sheet with only blank lines.
The lab gives you the data for this case, invented and generated for you alone.
Preparing your data…
Emeka: “Two different people are both called Ada. Your program merged them. How would I know?”
🔒 The debrief unlocks when you close the case. Finish the lab above.
The debrief
Emeka: “So cleaning the list can hide a real difference.”
What an experienced person would do next. Say in the report that two entries with the same name may be two people, and that the program cannot know: a name is a poor key. When there is a phone number or an email, use that as the key instead. Keep a list of what was removed and why (blank, repeat), not only a count, so that a person can check the removals. And never throw away the original file: clean a copy. Cleaning is a set of decisions, and each decision must be visible.
The trap. Comparing names without lower(), so that Ada and ADA stay as two people, and sorting without a key, so that “bola” lands after “Zed”.
Write the sign-up note
Write the note for the support engineer: how you cleaned the sheet (stripped the spaces, skipped blank lines, skipped repeats ignoring capitals with a set and kept the first spelling), how many lines you removed and how many different names remain, the sorted list rule (ignoring capitals), and the limit of the method (two different people with the same name look like one, so use a phone number or an email as the key and keep a list of what was removed).
🧪 Want to practise this on your own computer? See how to set up your lab →