Home / Blog / Word character & text counting

Text measurement methods

Count How Many Times Each Letter Appears

Build a letter-frequency table with a checked Banana example, Unicode normalization and an explicit rule for case, accents and nonletters.

Count How Many Times Each Letter Appears

To count how many times each letter appears, make a frequency table: the key is a letter and the value is its number of occurrences. This answers a different question from a total letter count. For Banana!, a case-insensitive Latin-letter table is a: 3, b: 1 and n: 2. The exclamation mark is excluded.

Choose the counting rule before counting

Decide whether uppercase and lowercase forms belong together, whether accented letters remain distinct, and whether digits or symbols should be excluded. For an ordinary letter-frequency exercise, keeping accents and excluding nonletters is a useful explicit rule. Removing accents would change the input’s spelling and can merge distinct letters in some languages.

Case-sensitive counting gives B: 1 for Banana, while case-insensitive counting gives b: 1. Both can be correct if labeled. Do not compare two tables without checking that they use the same rule. A sum of six letters should remain six for this example, whichever label is used for its initial letter.

Create a Unicode-aware table in Python

from collections import Counter
import unicodedata

text = "Banana!"
normalized = unicodedata.normalize("NFC", text).casefold()
counts = Counter(char for char in normalized if char.isalpha())
print(dict(sorted(counts.items())))
# {'a': 3, 'b': 1, 'n': 2}

NFC normalization combines equivalent accent sequences where Unicode provides a composed form. Case folding supports caseless matching more broadly than simply assuming ASCII uppercase letters. The alphabetic test excludes spaces, punctuation and digits. The result is sorted by character for a stable display, not by an assumed English alphabet for every writing system.

Case folding can expand a character. For example, German sharp s folds to two s characters. This script measures the normalized, case-folded sequence, so it is not a count of unchanged original code points. If that expansion is inappropriate for your task, retain case or choose a documented language-specific rule instead of hiding the difference.

Check a short sample by hand

  1. Write the sequence B, a, n, a, n, a.
  2. Choose to combine uppercase and lowercase forms.
  3. Add one to the b tally, three to a and two to n.
  4. Sum the frequencies: 1 + 3 + 2 = 6.
  5. Confirm that the punctuation contributed no letter.

As a second input, use Cab cab 2!. Under the same rule, a, b and c each appear twice. If the table still shows the Banana counts, the new text has not been processed. This second case also confirms that a space, a digit and punctuation do not enter the table.

Convert frequencies into proportions

For Banana, a accounts for 3 out of 6 letters, or 50 percent. The denominator is the six included letters, not the seven visible characters including punctuation. State that denominator when sharing percentages. Rounding each percentage can make the displayed percentages add to slightly above or below 100.

A high frequency is not by itself evidence of a spelling error, language identity or authorship. Very short samples vary sharply, and names or repeated headings can dominate a table. Use the frequencies as descriptive measurements of the chosen sample rather than conclusions about its writer.

Use the correct companion counter

The Letter Counter here reports a total number of letters. It does not promise this per-letter table. Use the script when you need each letter’s frequency, and use the total counter as a simple cross-check for an ordinary Latin sample such as Banana. Unicode normalization and case folding can cause deliberate differences on more complex input.

Retain the original text separately, record the normalization and case rules, and verify one accented sample if your real data uses accents. Never replace the source with its normalized analysis copy merely to simplify counting.

Implementation references

Python Counter and case folding document the operations used in the tested example.