Selecting a User from a List with PyInquirer

  • Share this:

Code introduction


This function uses the prompt method from the PyInquirer library to select a user from a given list.


Technology Stack : PyInquirer

Code Type : User selection function

Code Difficulty : Intermediate


                
                    
def select_random_user(input_list):
    import random
    from pyinquirer import prompt

    questions = [
        {
            "type": "list",
            "name": "user",
            "message": "Select a user from the list:",
            "choices": input_list
        }
    ]

    answer = prompt(questions)
    return answer["user"]                
              
Tags: