diff --git a/snippets/digitize.md b/snippets/digitize.md new file mode 100644 index 000000000..cc11f843c --- /dev/null +++ b/snippets/digitize.md @@ -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] +```