The problem
A log of station codes has many repeats. Return a new list that keeps the first appearance of each code and drops the later ones. Keep the codes in the order they first appeared. Do not change codes.
dedupe(["BCT", "HWH", "BCT", "MAS", "HWH"])
# ["BCT", "HWH", "MAS"]
dedupe([]) # []
list(set(codes)) removes repeats but loses the order. Lesson 8 explains why if c not in out is too slow here.
Limits
- Up to 100,000 codes.
Builds on BIGO-4 Space cost and BIGO-8 Python’s hidden costs.
Continue on a laptop
Practice runs Python in the browser and needs a keyboard and a wider screen. Read the problem and open hints here, then write your solution on a laptop. Progress is saved per browser for now, so hints opened here stay on this device.
Need a hint?0 of 3 opened
- Hint 1Nudge
- Hint 2Approach Open hint 1 first
- Hint 3Pseudocode Open hint 2 first
- Worked solutionlast resort Opens after all 3 hints
Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | Repeats | Not run | |
| 2 | No repeats | Not run | |
| 3 | All the same | Not run | |
| 4 | Empty | Not run | |
| 5 | Input not changed | Not run | |
| 6 | 100,000 codes, half repeated | Not run |