Solution 1

# Import the library here!
import random

def get_random_list_element(a_list):
    return random.choice(a_list)

Get Random List Element

Time to practice using the Standard Library (stdlib)!

Let's start with the random library.

Import the random library and write a function get_random_list_element that receives the list a_list and returns a random element from that list.

Hint: You'll have to look up the documentation to decide which method of the random library to use to solve this assignment.


get_random_list_element(["hats", "shoes", "pants", "scarf", "shirt"]) # "shoes"

get_random_list_element(["hats", "shoes", "pants", "scarf", "shirt"]) # "shirt"

Test Cases

test random element - Run Test

def test_random_element():
    assert get_random_list_element([1, 2, 3, 4, 5]) in [1, 2, 3, 4, 5]
# Import the library here! def get_random_list_element(a_list): pass