Random Word Generator by Language

  • Share this:

Code introduction


This function takes two arguments: a list of languages and a number. It randomly selects a language from the list and generates a specified number of random words using the Lingua library.


Technology Stack : Lingua

Code Type : Python Function

Code Difficulty : Intermediate


                
                    
import random

def random_word_language(arg1, arg2):
    languages = arg1
    num_words = arg2
    
    if not isinstance(languages, list) or not isinstance(num_words, int):
        return "Invalid input: languages should be a list and num_words should be an integer."
    
    selected_language = random.choice(languages)
    word_list = lingua.random_words(language=selected_language, num=num_words)
    
    return word_list                
              
Tags: