Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Count Letter Frequencies

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

Your question is Count Letter 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

SWIFT message fields can contain letters, spaces, digits, and punctuation. Implement a function that counts how many times each alphabetic letter appears in a message, ignoring case and non-letter characters.

Return the counts as a dictionary whose keys are lowercase letters. The keys must appear in alphabetical order in the returned dictionary. Include only letters that occur at least once.

Formal Specification

  • Input: A string message containing zero or more ASCII characters.
  • Output: A dictionary mapping each lowercase letter to its frequency.
  • Treat uppercase and lowercase versions of the same letter as identical.
  • Ignore digits, whitespace, punctuation, and other non-alphabetic characters.

Constraints

  • 0 <= len(message) <= 10^5
  • Input contains ASCII characters
  • The output contains at most 26 keys

Function Signature

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