Skip to content

Instantly share code, notes, and snippets.

@stoggi
Created November 17, 2015 02:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stoggi/fd2c2e7bc24c49e3b852 to your computer and use it in GitHub Desktop.
Save stoggi/fd2c2e7bc24c49e3b852 to your computer and use it in GitHub Desktop.
Calculates the number of repeated characters in a given text
from collections import defaultdict
def character_frequency(text):
frequency = defaultdict(int)
for character in text:
frequency[character] += 1
return frequency
character_frequency("Hello World!!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment