Menu
Coddy logo textTech

Word Analytics

Part of the Logic & Flow section of Coddy's Python journey — lesson 77 of 78.

challenge icon

Challenge

Hard

Create a function named analyze_text that analyzes words in a text string.

Your function should:

  1. Count unique words (case-insensitive)
  2. Find all words that appear more than once
  3. Identify all palindrome words (words that read the same forwards and backwards, like "level")

Return a dictionary with three keys:

  • unique_count: the number of unique words (count also repeated words once each)
  • repeated_words: a sorted list of words appearing more than once
  • palindromes: a sorted list of palindrome words

Notes:

  • Treat words as case-insensitive (e.g., "Hello" and "hello" are the same word)
  • Remove any punctuation (.,!?:;"()) from words
  • Sort both the repeated_words and palindromes lists alphabetically

Example Input:

"Madam saw a racecar. Dad said hello hello to mom."

Expected Output:

{
    'unique_count': 9,
    'repeated_words': ['hello'],
    'palindromes': ['a', 'dad', 'madam', 'mom', 'racecar']
}

Try it yourself

def analyze_text(text):
    # Your solution here
    
    # 1. Split the text into words and normalize them
    # (make lowercase and remove punctuation)
    
    # 2. Count the occurrences of each word
    
    # 3. Find the number of unique words
    
    # 4. Identify repeated words (appearing more than once)
    
    # 5. Find palindrome words
    
    # 6. Return the results in a dictionary with sorted lists
    pass

All lessons in Logic & Flow