Files
30-seconds-of-code/snippets/sample.md
Isabelle Viktoria Maciohsek 0f7214ba1c Update sample
2020-10-28 11:45:34 +02:00

262 B

title, tags
title tags
sample list,random,beginner

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