EasyListsNot started

Unique route stops

A bus route export repeats stops when two schedule fragments overlap. Read the comma-separated stop names and print each stop once, preserving the order in which it first appeared.

Input

One line of 1 to 30 lowercase stop names separated by commas.

Output

One line: the unique stop names separated by -> .

Example 1

Input

harbour,mill,park,mill,station

Output

harbour -> mill -> park -> station

The second mill is omitted without changing the other order.

Constraints

  • Every name has 1 to 20 lowercase letters
  • At least one stop is present

Hints

Hint 1 of 3

split(',') creates the input list.

Hint 2 of 3

Append a stop only when it is not already in the result list.

Hint 3 of 3

Use ' -> '.join(...) for the required output.

Solution

Show a reference solution and explanation
 Python · reference solution
stops = input().strip().split(",")
unique = []
for stop in stops:
    if stop not in unique:
        unique.append(stop)
print(" -> ".join(unique))

Why it works

Scanning from left to right and appending only unseen values preserves first appearance automatically. A set would speed up large inputs, but the list-only version clearly demonstrates ordered de-duplication for this small constraint.

Lesson for this exercise: Lists in Python

Your program
stops = input().strip().split(",")
unique = []
# keep only the first occurrence of each stop
print(" -> ".join(unique))

Tests: 3 cases including the examples. Passing every test marks the exercise solved in this browser.

Ready for a challenge?

How this page was checked. Every program on it was run with CPython 3.11 at build time; runs in your browser on CPython 3.14 (Pyodide) by the publishing checks, and the output shown is what it printed. The Run buttons execute the same code on your device; nothing you type is sent anywhere.