Files
30-seconds-of-code/snippets/digitize.md
Angelos Chalaris 852007e276 Add digitize snippet
2019-08-20 13:00:27 +03:00

18 lines
292 B
Markdown

---
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]
```