-
Notifications
You must be signed in to change notification settings - Fork 11
Random Word
The random_word sub-module exclusively deals with getting random English words and contains the random_word class which has 3 functions: word(), words_list() and starts_with(). This page explains all of the functions of the random_word sub_module as well as instructions on how to import it and tips for easier use.
an asterisk is used to denote optional parameters (*)
Before you use any of the functions in this sub-module, you must import it in the following way:
from wonderwords import random_word
or alternatively:
import wonderwords.random_word
If you get a ModuleNotFoundError
, that means you either didn't install the wonderwords package or something went wrong on our side. If so, please let us know.
The word() function is ideal for getting random words if you ever need them in a python program.
word(*include_parts_of_speech, *word_min_length, *word_max_length)
include_parts_of_speech - (optional) str: to specify which parts of speech to include (noun, adjective, verb). If more than one, separate with a comma
word_min_length - (optional) int: to specify the minimum amount of characters in the word
word_max_length - (optional) int: to specify the maximum amount of characters in the word
A random English word
from wonderwords import random_word
english_word = random_word.random_word()
# Set variable a_random_word to a random English noun or verb:
a_random_word = english_word.word('noun, verb')
The words_list() function returns a list of random words. You pass a parameter as the number of words the list should contain.
words_list(amountamount, *include_parts_of_speech, *word_min_length, *word_max_length)
amount - (required) int: to specify the amount of words the function returns in a list.
include_parts_of_speech - (optional) str: to specify the part of speech (noun, verb, adjective). If more than one, separate with a comma
word_min_length - (optional) int: to specify the minimum amount of characters in the word
word_max_length - (optional) int: to specify the maximum amount of characters in the word
A list of English words.
from wonderwords import random_word
english_word = random_word.random_word()
# Set variable six_random_words to a list of 6 random adjectives:
six_random_words = english_word.words_list(6, 'adjective')
The function starts_with() returns a random word that starts with a certain letter passed as a parameter.
starts_with(letter, *include_parts_of_speech, *word_min_length, *word_max_length)
letter - (required) int: specifies the first letter of the random word the function returns
include_parts_of_speech - (optional) str: specifies the part of speech of the random word (noun, verb, adjective). If multiple, separate with commas.
word_min_length - (optional) int: to specify the minimum amount of characters in the word
word_max_length - (optional) int: to specify the maximum amount of characters in the word
A random English word that starts with a certain letter
from wonderwords import random_word
english_word = random_word.random_word()
# Set variable random_d_word to a random noun or adjective that starts with d:
random_d_word = english_word.starts_with('d', 'noun, adjective')
⚠️ This documentation will no longer be updated, as Wonderwords version 2 is now out. You can find the new documentation at https://wonderwords.readthedocs.io
⚠️ This documentation will no longer be updated, as Wonderwords version 2 is now out. You can find the new documentation at https://wonderwords.readthedocs.io