Last active
August 29, 2015 14:24
-
-
Save debetimi/92888dfe500b24867fc3 to your computer and use it in GitHub Desktop.
Top ten most frequent letters in a string.
This file contains 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
def character_frequency(words): | |
words = words.upper().split(' ') | |
counts = [0] * 26 | |
for word in words: | |
for char in word: | |
counts[ord(char) - ord('A')] += 1 | |
letters = [chr(x+ord('A')) for x in range(26)] | |
return sorted(zip(counts, letters))[-1: -11: -1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment