Files
30-seconds-of-code/snippets/sample.md
Isabelle Viktoria Maciohsek cbc78ee450 Bake dates into snippets
2021-06-13 19:38:10 +03:00

22 lines
338 B
Markdown

---
title: sample
tags: list,random,beginner
firstSeen: 2019-08-20T16:02:37+03:00
lastUpdated: 2020-10-28T11:45:34+02:00
---
Returns a random element from a list.
- Use `random.choice()` to get a random element from `lst`.
```py
from random import choice
def sample(lst):
return choice(lst)
```
```py
sample([3, 7, 9, 11]) # 9
```