Most common word in a support ticket

Python data engineering interview problem. Difficulty: beginner. Pattern: Strings. About 10 minutes. Free to practice.

Support tickets arrive as messy free text. A triage job needs the single most common word so agents can tag the queue (login, refund, shipping) without reading every ticket.

Support tickets are written by real people, so the same word shows up as Red, red and RED, and punctuation sticks to words. A report needs the one word that appears most often. Make the text lowercase, keep only letters and digits as words, count each word, and return the most frequent word (the word with the highest count). If 2 words have the same count, return the one that comes first alphabetically. If there are no words, return an empty string. Write most_common_word(text). In 'Red red BLUE blue blue' the word blue appears 3 times and red 2 times, so the answer is 'blue'. In 'a a b b' both words appear twice, so the answer is 'a'. The starter file already has the function name and its print lines. Keep them and fill in the body.

Requirements

  • Treat upper and lower case as the same word.
  • Ignore punctuation, so blue, counts as blue.
  • Return the word with the highest count.
  • On a tie, return the alphabetically first word.
  • Return '' when there are no words.

Constraints

  • text is a string.
  • The result is a lowercase string.
  • Words are made of letters and digits only.

Examples

Input: most_common_word('Red red BLUE blue blue') Output: 'blue' This input follows the stated rules and produces this output.

Topics: lakebench, python, strings.

More Python interview questions · All interview problems · Learn data engineering

beginner

Most common word in a support ticket

Interview-style drill: Given a block of ticket text, return the single most frequent word.

From a block of ticket text, return the one most frequent word after normalizing case and dropping punctuation.