Files
30-seconds-of-code/snippets/sample.md
2022-12-04 22:24:48 +02:00

383 B

title, tags, cover, firstSeen, lastUpdated
title tags cover firstSeen lastUpdated
Random element in list list,random blog_images/walking-on-top.jpg 2019-08-20T16:02:37+03:00 2020-10-28T11:45:34+02:00

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