Add digitize snippet
This commit is contained in:
17
snippets/digitize.md
Normal file
17
snippets/digitize.md
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
---
|
||||||
|
title: digitize
|
||||||
|
tags: math,list,beginner
|
||||||
|
---
|
||||||
|
|
||||||
|
Converts a number to an array of digits.
|
||||||
|
|
||||||
|
Use `map()` combined with `int` on the string representation of `n` and return a list from the result.
|
||||||
|
|
||||||
|
```py
|
||||||
|
def digitize(n):
|
||||||
|
return list(map(int, str(n)))
|
||||||
|
```
|
||||||
|
|
||||||
|
```py
|
||||||
|
digitize(123) # [1, 2, 3]
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user