Random element in list

Returns a random element from a list.

  • Use random.choice() to get a random element from lst.
from random import choice

def sample(lst):
  return choice(lst)
sample([3, 7, 9, 11]) # 9