Last active
January 5, 2022 14:11
-
-
Save scmbradley/ca18a61a982131fa9270b93a8d79f3bf to your computer and use it in GitHub Desktop.
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
from collections import Counter | |
# Download a wordlist such as the one available here: | |
# https://github.com/dwyl/english-words | |
with open("../resources/words/words_alpha.txt") as d: | |
wl = [x.strip() for x in d.readlines()] | |
firsts = [x[0] for x in wl] | |
fives = [x for x in wl if len(x) == 5] | |
def top_letters(ctr, n=10): | |
return ",".join([x[0].upper() for x in ctr.most_common(n)]) | |
print("For all words in the list") | |
print("Most common first letters") | |
print(top_letters(Counter(firsts))) | |
print("Most common all positions") | |
print(top_letters(Counter("".join(wl)))) | |
print("For five letter words:") | |
for i in range(5): | |
print(f"Top letters in position {i}") | |
letters = [x[i] for x in fives] | |
print(top_letters(Counter(letters))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment