You can download this code by clicking the button below.
This code is now available for download.
This function takes a list of words and returns a random word with length between the specified minimum and maximum length.
Technology Stack : Textual, random
Code Type : Function
Code Difficulty : Intermediate
def random_word_length(word_list, min_length, max_length):
"""
This function takes a list of words and returns a random word with length between min_length and max_length.
"""
import random
from textual import random
def get_word_length(word):
return len(word)
filtered_words = filter(lambda word: min_length <= get_word_length(word) <= max_length, word_list)
return random.choice(list(filtered_words))
# JSON representation