First Duplicate
Completed
Read a line of words and print the first word that appears for the second time. If none repeats, print none.
Input
One line.
Output
A word or none.
Example
Input
a b c b a
Output
b
Editor
Python
Hints
Keep a set of words already seen.
Checking x in a set is very fast.
Solution explanation
Membership tests on a set take constant time, unlike lists which must be scanned.
Show solution
seen = set()
for w in input().split():
if w in seen:
print(w)
break
seen.add(w)
else:
print("none")