Skip to content

Instantly share code, notes, and snippets.

@debetimi
Last active August 29, 2015 14:24
Show Gist options
  • Save debetimi/92888dfe500b24867fc3 to your computer and use it in GitHub Desktop.
Save debetimi/92888dfe500b24867fc3 to your computer and use it in GitHub Desktop.
Top ten most frequent letters in a string.
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