Final 1: one row per supplier
AI off This is a final exam, matched to the baseline exam you did in the first module: the same kind of problem, new data, the same difficulty. The tutor is switched off and there are no hints. Work alone. The course lines it up against your baseline in the next lesson.
Finance has three years of supplier records from two old systems and wants one row per supplier before the next payment run. The same firm appears with "Ltd" and "Limited", with tax numbers typed with spaces and dots, and in different cities when a branch registered separately.
The worked example
1 Granite Tools Ltd GB 123 456.789 Leeds
2 GRANITE TOOLS LIMITED (none) leeds
3 Granite Tools Ltd. gb-123456789 Cork
4 Granite Tools plc IE1234567X Cork
5 granite tools ie 1234567x Dublin
6 Oak Paper (none) Lyon
7 Swift Glass (none) Porto
8 Oak Paper plc FR 99 887 Brno
# -> [[1, 2, 3, 4, 5], [6], [7], [8]]Write merge_suppliers(records). Each record is a dict with "id" (a unique whole number), "company", "vat" (a tax number) and "city". Return a list of groups, one per real supplier; each group is a list of ids, and every id appears in exactly one group. Order does not matter.
- VAT rule: two records are the same supplier if their VAT numbers match after you remove spaces, dots and dashes and uppercase (
gb-123 456.789isGB123456789). An empty VAT number matches nothing. - Name rule: they are also the same supplier if their company names match after you remove dots and commas, lowercase, split into words and drop a last word that is
ltd,limitedorplc, and their cities match after trimming and lowercasing. - Chains: if A matches B and B matches C, all three are one supplier, 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.