livepython.net

125. Python Program to Find the First Repeated Word

MediumSets

Overview

A set is a perfect memory: "have I seen this word before?" is one in check.

Problem Statement

Read one line of words separated by spaces. Going from left to right, find the first word that appears for the second time, and print it. For example, in one two three two one, the word two is the first one met again:

First repeated word: two

If no word appears twice, print:

No repeated words

Capital letters matter: Go and go are different words.

Use input() with no prompt text: the tests type the input for you, and a prompt would end up in your output.

Input

One line of words. Example:

one two three two one

Output

The output for that example:

First repeated word: two

The tests try 4 different inputs.

Learn this firstChapter 14 · Python Sets: Unique Items, add(), remove() and in
solution.py
# write your code here

EXPECTED OUTPUT

1First repeated word: two

YOUR OUTPUT

Press Run to see your output here. Lines are compared with the expected output.