Files
30-seconds-of-code/snippets/digitize.md
2020-09-15 16:25:15 +03:00

292 B

title, tags
title tags
digitize math,list,beginner

Converts a number to a list of digits.

  • Use map() combined with int on the string representation of n and return a list from the result.
def digitize(n):
  return list(map(int, str(n)))
digitize(123) # [1, 2, 3]