From 852007e2769c014b6349f986f31c67e314e776b0 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 20 Aug 2019 13:00:27 +0300 Subject: [PATCH] Add digitize snippet --- snippets/digitize.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/digitize.md 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] +```