Skip to content

Home

Random element in list

Returns a random element from a list.

from random import choice

def sample(lst):
  return choice(lst)

sample([3, 7, 9, 11]) # 9

More like this

Start typing a keyphrase to see matching snippets.