The problem
A log lists the station code of every train that passed. Return a list of the codes that appear exactly once in the log, in the order they appear.
single_codes(["BCT", "HWH", "BCT", "MAS", "HWH", "SBC"])
# ["MAS", "SBC"]
single_codes(["A", "B", "A", "B"]) # []
single_codes([]) # []
Limits
- Up to about 300,000 codes.
Builds on PYTH-4 Dicts, sets and tuples.
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.
7 tests, not run yet
| # | Test | Result | Reads · time |
|---|---|---|---|
| 1 | A few codes | Not run | |
| 2 | Order kept | Not run | |
| 3 | All repeated | Not run | |
| 4 | No repeats | Not run | |
| 5 | Empty list | Not run | |
| 6 | Three times | Not run | |
| 7 | 300,000 codes | Not run |