How to use 'word generator from letters' in Python

Every line of 'word generator from letters' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
13def draw_letters():
14 """Pick NUM_LETTERS letters randomly. Hint: use stdlib random"""
15 return random.sample(POUCH, NUM_LETTERS)
152def get_random_word(dictionary, starting_letter=None):
153 """
154 Takes the dictionary to read from and returns a random word
155 optionally accepts a starting letter
156 """
157 if starting_letter is None:
158 starting_letter = random.choice(list(dictionary.keys()))
160 try:
161 to_return = random.choice(dictionary[starting_letter])
162 except KeyError:
163 msg = "Dictionary does not contain a word starting with '{}'"
164 raise NoWordForLetter(msg.format(starting_letter))
166 return to_return

Related snippets