Skip to content

Random Word

Maxim R edited this page Mar 25, 2020 · 8 revisions

The random_word Sub-module

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 (*)


Table of contents


Import

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.


word()

The word() function is ideal for getting random words if you ever need them in a python program.

Syntax

word(*include_parts_of_speech, *word_min_length, *word_max_length)

Parameters

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

Returns

A random English word

Example

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')

words_list()

The words_list() function returns a list of random words. You pass a parameter as the number of words the list should contain.

Syntax

words_list(amountamount, *include_parts_of_speech, *word_min_length, *word_max_length)

Parameters

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

Returns

A list of English words.

Example

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')

starts_with()

The function starts_with() returns a random word that starts with a certain letter passed as a parameter.

Syntax

starts_with(letter, *include_parts_of_speech, *word_min_length, *word_max_length)

Parameters

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

Returns

A random English word that starts with a certain letter

Example

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

Clone this wiki locally