Last active
December 18, 2016 08:10
-
-
Save MostAwesomeDude/d57e32ae3b035a437e3a6a16c8450255 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 defaultdict | |
import string | |
words = open("wordsEn.txt", "rb").read().split("\r\n") | |
words.sort(key=lambda k: (-len(k), k)) | |
def longestWordsByLetter(k): | |
remaining = dict((c, k) for c in string.lowercase) | |
rv = defaultdict(list) | |
for word in words: | |
if not remaining: | |
break | |
else: | |
c = word[0] | |
if c in remaining: | |
rv[c].append(word) | |
remaining[c] -= 1 | |
if not remaining[c]: | |
del remaining[c] | |
return dict(rv) | |
print longestWordsByLetter(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment