Skip to content

Instantly share code, notes, and snippets.

@trainman419
Created March 25, 2019 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trainman419/9a0d122f45d05c6ffec60a2efaeb2789 to your computer and use it in GitHub Desktop.
Save trainman419/9a0d122f45d05c6ffec60a2efaeb2789 to your computer and use it in GitHub Desktop.
word salad
#!/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