A set can tell whether a value has been seen, while a list can preserve the order of the first visit.
Detect a repeated badge number while scanning arrivals.
seen = set()
for badge in [7, 9, 7]:
if badge in seen:
print("Already scanned:", badge)
seen.add(badge)
# Already scanned: 7Check membership before adding the current badge. For a list of first visits, record an item on its first appearance.
Return the distinct station names in the order they first occur. Repeated visits to the same station should not appear twice.
first_visits(["B", "A", "B", "C", "A"]) # ["B", "A", "C"]