QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Count Character Frequency

Counts the frequency of each character in a string

  • string
  • character
  • frequency
  • character-frequency

Code

from collections import Counter

def char_frequency(s):
    return dict(Counter(s))

Usage

System.out.println(characterFrequency("hello world", false, false)); // {r=1, d=1, e=1, w=1, h=1, l=3, o=2}