Created
November 17, 2015 02:13
-
-
Save stoggi/fd2c2e7bc24c49e3b852 to your computer and use it in GitHub Desktop.
Calculates the number of repeated characters in a given text
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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