Problem

Description

Given a random non-negative number, you have to return the digits of this number within an array in reverse order.

Test Cases

digitize(35231) # returns [1,3,2,5,3]
digitize(0) # returns [0]

Solution

My Solution

def digitize(n):
    n = list(str(n))
    return [int(i) for i in n[::-1]]

Other Solutions

def digitize(n):
    return [int(x) for x in str(n)[::-1]]

Learning Experiences

  • Me when I forget that strings are iterable (which is why they can be sliced, etc.), so the list() is entirely unnecessary.
    • Besides, using list comprehension also means that a list is returned anyways!