PYTH-P4

The codes seen once

Practice 4 of 5Python for DSA7 tests

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

  1. Hint 1Nudge
  2. Hint 2Approach Open hint 1 first
  3. Hint 3Pseudocode Open hint 2 first
  4. Worked solutionlast resort Opens after all 3 hints
Python waits for a wider screensolution.py

Ctrl + Enter runs the tests. Tab indents; press Esc, then Tab, to leave the editor.

7 tests, not run yet
Test results
#TestResultReads · time
1A few codesNot run
2Order keptNot run
3All repeatedNot run
4No repeatsNot run
5Empty listNot run
6Three timesNot run
7300,000 codesNot run