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
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