Retired

Character frequency (retired)

1,424 of 2,571Svenito

Description:

Write a function that takes a piece of text in the form of a string and returns the letter frequency count for the text. This count excludes numbers, spaces and all punctuation marks. Upper and lower case versions of a character are equivalent and the result should all be in lowercase.

The function should return a list of tuples (in Python and Haskell) or arrays (in other languages) sorted by the most frequent letters first. The Rust implementation should return an ordered BTreeMap. Letters with the same frequency are ordered alphabetically. For example:

  letter_frequency('aaAabb dddDD hhcc')
  letterFrequency "aaAabb dddDD hhcc"
  letterFrequency('aaAabb dddDD hhcc')
  letter_frequency('aaAabb dddDD hhcc')
  letter_frequency("aaAabb dddDD hhcc")
  letter_frequency("aaAabb dddDD hhcc")

will return

  [('d',5), ('a',4), ('b',2), ('c',2), ('h',2)]
  [('d',5), ('a',4), ('b',2), ('c',2), ('h',2)]
  [['d',5], ['a',4], ['b',2], ['c',2], ['h',2]]
  [['d',5], ['a',4], ['b',2], ['c',2], ['h',2]]
  [('d',5), ('a',4), ('b',2), ('c',2), ('h',2)]
  std::vector<std::pair<char, size_t>>{{'d',5}, {'a',4}, {'b',2}, {'c',2}, {'h',2}}

Letter frequency analysis is often used to analyse simple substitution cipher texts like those created by the Caesar cipher.

Strings
Algorithms

More By Author:

Check out these other kata created by Svenito

Stats:

CreatedAug 11, 2014
Warriors Trained5310
Total Skips675
Total Code Submissions17277
Total Times Completed2571
Python Completions1424
JavaScript Completions586
Ruby Completions194
Rust Completions294
C++ Completions99
Haskell Completions40
Total Stars130
% of votes with a positive feedback rating94% of 455
Total "Very Satisfied" Votes403
Total "Somewhat Satisfied" Votes45
Total "Not Satisfied" Votes7
Ad
Contributors
  • Svenito Avatar
  • jhoffner Avatar
  • GiacomoSorbi Avatar
  • kazk Avatar
  • JohanWiltink Avatar
  • LesnyRumcajs Avatar
  • tzdybal Avatar
  • user8436785 Avatar
Ad