Created
March 25, 2019 17:12
-
-
Save trainman419/9a0d122f45d05c6ffec60a2efaeb2789 to your computer and use it in GitHub Desktop.
word salad
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
#!/usr/bin/env python | |
import sys | |
import collections | |
import random | |
words_by_first = collections.defaultdict(list) | |
with open('/usr/share/dict/words') as words: | |
for word in words.readlines(): | |
word = word.strip() | |
words_by_first[word[0]].append(word) | |
first = True | |
out = '' | |
for c in sys.argv[1]: | |
c = c.lower() | |
if c == ' ': | |
continue | |
else: | |
if c in words_by_first: | |
w = random.choice(words_by_first[c.lower()]) | |
if first: | |
out += w.capitalize() | |
first = False | |
else: | |
out += w | |
else: | |
out += c | |
out += ' ' | |
print out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment