easy +8 pts

Find repeated words

Identify words that appear more than once in a sentence or list of sentences.

Write a function `find_repeated_words(text: str) -> list[str]` that takes a string `text` and returns a list of unique words (lowercase, sorted alphabetically) that appear **more than once** in the text. **Rules:** - Split the text into words using any whitespace (spaces, tabs, newlines). Punctuation attached to a word (like `word!` or `'word'`) is part of the word. Do not strip punctuation. - The comparison is **case-insensitive**: `Hello` and `hello` are the same word. The returned words must be in lowercase. - Each word appears only once in the output. - If no word repeats, return an empty list. **Examples:** - `find_repeated_words("apple banana apple")` → `["apple"]` - `find_repeated_words("The cat and the dog.")` → `["the"]` (because `The` and `the` are the same) - `find_repeated_words("one two three")` → `[]`

Constraints

- `0 <= len(text) <= 1000` - The text may contain any printable characters. - Words are separated by whitespace. - Return list is sorted alphabetically (standard Python string sort).

Example

>>> find_repeated_words("apple banana apple")
['apple']
>>> find_repeated_words("The cat and the dog.")
['the']
>>> find_repeated_words("one two three")
[]
>>> find_repeated_words("a A a")
['a']
>>> find_repeated_words("")
[]
8 points ~12 min

Recent Submissions

No submissions yet — hit Run Tests to try!

Hints

Split the text into words using `text.split()`.
Convert each word to lowercase before counting so the comparison is case-insensitive.
Use a dictionary to count occurrences, then filter those with count > 1 and sort the keys.
Python 3
All tests passed!
Test Results
Press Ctrl+Enter or click Run Tests to execute your code.