Baseline 1: one row per customer
AI off This is a baseline exam. The tutor is switched off and there are no hints. Work alone, the way you would with no assistant open. Nothing here is a trick: every rule is written in the exercise. Your result is only compared with your own final exam at the end of the course.
A shop is moving to a new system and wants one row per customer. Over the years the same person signed up from different devices, with capital letters, stray spaces and email tags. Some changed email but kept their name and postcode.
The worked example
1 Ada Okafor ada.okafor@mail.com N1 9GU
2 ADA okafor Ada.Okafor+news@Mail.com n19gu
3 Ada Okafor ada@work.org N1 9GU
4 A. Okafor ADA@work.org E2 7RT
5 Tom Berg (no email) SW1A 1AA
6 Sade Dube (no email) M1 1AE
7 tom berg tberg@mail.com sw1a1aa
8 Tom Berg tberg@mail.com LS1 4AP
# -> [[1, 2, 3, 4], [5, 7, 8], [6]]Write merge_customers(records). Each record is a dict with "id" (a unique whole number), "name", "email" and "postcode". Return a list of groups, one per real customer; each group is a list of ids, and every id appears in exactly one group (a customer with no duplicates is a group of one). Order does not matter.
- Email rule: two records are the same customer if their emails match after you trim spaces, lowercase, and drop a
+tagfrom the part before@(Ada.Okafor+news@Mail.comisada.okafor@mail.com). An empty email matches nothing. - Name rule: they are also the same customer if their names match after lowercasing and collapsing spaces, and their postcodes match after removing spaces and uppercasing.
- Chains: if A matches B and B matches C, all three are one customer, even if A and C share nothing.
steps(), lines of your own code).
AI off: no tutor, hints or worked solution on this one. Your own thinking only.
Spotted a problem in this lesson? Report it · Ask about this lesson
This exercise opens soon
Finish the lesson before it and this one unlocks. The whole course is free, no account needed, and you can read this lesson right now.
This browser is blocking cookies for learn.floati.life, so lessons you finished here cannot open in order. Allow cookies for this site and reload.