beginner

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.

45 min

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, and text == "" tests for empty. A string that only has spaces is empty after strip().
  • A set remembers. seen = set() starts an empty set; seen.add(key) puts a value in; key in seen answers “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 in seen, 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 run clean on 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…

🔒 The debrief unlocks when you close the case. Finish the lab above.

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).

0 words

🧪 Want to practise this on your own computer? See how to set up your lab →

🤖

Need clarification? Ask GT

Hi, I'm GT — your AI tutor for Case File: The Sign-Up Sheet. What would you like to know?
📝

Knowledge Check

1 of 3

What is a set good for?

⚑ Capture The Flag

Report a problem

About: /lessons/case-the-clean-list