Skip to contentKEEP THE CRAFTTHE SANCTUARY

Track Previously Seen Values

Report for each value whether it appeared earlier, using a set: look back first, then store.

The problem

Implement track_seen_values(values). Return a list of booleans with one entry per input value. An entry is True exactly when the same value appeared at an earlier index; the first time a value appears, its entry is False. For example, [4, 1, 4, 4, 2, 1] gives [False, False, True, True, False, True].

Starter code

def track_seen_values(values):
    pass

Public examples

  1. values = [4, 1, 4, 4, 2, 1]gives[False, False, True, True, False, True]
  2. values = ["a", "b", "c"]gives[False, False, False]

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.