BIGO-P3

Keep the first of each

Practice 3 of 5Cost: Big-O and friends6 tests

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

  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.

6 tests, not run yet
Test results
#TestResultReads · time
1RepeatsNot run
2No repeatsNot run
3All the sameNot run
4EmptyNot run
5Input not changedNot run
6100,000 codes, half repeatedNot run