Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Normalize and Count Word Frequencies

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Normalize and Count Word Frequencies. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Given a string text, write a function that returns a dictionary mapping each word to its frequency. Treat words case-insensitively, ignore punctuation, and split on any non-alphanumeric character. Return the result as a standard Python dictionary where keys are normalized lowercase words and values are counts.

Constraints

  • 0 <= len(text) <= 10^5
  • text contains ASCII letters, digits, spaces, punctuation, and underscores
  • Output keys must be lowercase strings with no empty tokens included

Function Signature

def count_word_frequencies(text):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output