Last active
June 13, 2016 00:57
-
-
Save jweede/3dd70a541b642605214b2106a580cf71 to your computer and use it in GitHub Desktop.
What does BDT stand for?
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 python2 | |
import string | |
import random | |
class BDTGen(object): | |
def __init__(self): | |
self.words_dict = { | |
letter: [] | |
for letter in string.letters | |
} | |
self.build_dict() | |
self.random = random.SystemRandom() | |
def build_dict(self, words_file='/usr/share/dict/words'): | |
with open(words_file, 'r') as fp: | |
for line in fp: | |
word = line.strip().lower() | |
letter = word[0] | |
self.words_dict[letter].append(word) | |
def random_word_by_letter(self, letter): | |
return self.random.choice(self.words_dict[letter]) | |
def random_bdt(self): | |
return ' '.join(map(self.random_word_by_letter, 'bdt')) | |
x = BDTGen() | |
for _ in range(20): | |
print(x.random_bdt()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output: