Exercise 6: The First Repeated Word — Possible Solution ==================================================================== sentence = "The cat saw the dog and the bird" seen = [] repeat = None for word in sentence.lower().split(): if word in seen: repeat = word break seen.append(word) if repeat is None: print("No repeated word") else: print(f"First repeat: {repeat!r} after {len(seen)} different words") Example run: First repeat: 'the' after 3 different words WHY THIS WORKS AS AN ANSWER ------------------------------ lower() makes 'The' and 'the' the same word before they are compared. Each new word is remembered in seen; the first word that is already in seen is the answer, so the loop records it and breaks. Without the break, the loop would carry on and overwrite repeat every time it met another already-seen word. This sentence would still say 'the', but 'a b a b' would give 'b' instead of the first repeat, 'a'. A for/else would handle 'not found' but cannot hand the word to the code after the loop, which is why a variable that starts as None is used. Note the test is 'is None', not '== None' or a truthiness check.