30 seconds of python

  Back to Home

sample

listrandombeginner

Returns a random element from an array.

Use randint() to generate a random number that corresponds to an index in the list, return the element at that index.

from random import randint

def sample(lst):
  return lst[randint(0, len(lst) - 1)]