Most common review word

strings

Most common review word

Etsy Python Interview Question

Etsy's seller insights team picks out the word buyers use most in a review, ignoring filler words such as "the".

Write a function most_common_word(review, stop_words) that returns the word that appears most often in the review. Treat capital and lowercase letters as the same, treat anything that is not a letter as a break between words, and ignore any word in the stop word list. If several words tie, return the one that comes first alphabetically. Return the word in lowercase.

Asked of

  • Data Engineer
  • Data Scientist
  • Analytics Engineer
  • ML Engineer
  • AI Engineer

Example 1

Input

most_common_word("Great mug. Great price, fast shipping!", ["the", "a"])

Output

"great"

Example 2

Input

most_common_word("Love it, love the color", ["the"])

Output

"love"

Explanation

In the first example, "Great" and "great" count as the same word, which appears twice, while every other word appears once. The punctuation after "mug" and "price" is not part of either word.

Submit also runs 3 hidden test cases that check edge cases.