Nest all content into snippets
This commit is contained in:
23
snippets/python/s/sample.md
Normal file
23
snippets/python/s/sample.md
Normal file
@ -0,0 +1,23 @@
|
||||
---
|
||||
title: Random element in list
|
||||
type: snippet
|
||||
language: python
|
||||
tags: [list,random]
|
||||
cover: walking-on-top
|
||||
dateModified: 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
|
||||
```
|
||||
Reference in New Issue
Block a user