python: recursion a sequence number into the reverse list

Connected to the back: the inverse number sequence into a list, for example, 1234 => [4,3,2,1]. Required to achieve with recursion.
Str not allowed and the map, and then to do directly with the modulo division:

lst = []

def int_to_list(tmp:int):
    division_number = tmp / 10
    demo_number = tmp % 10
    tmp3 = division_number - demo_number / 10
    if tmp3:
        int_to_list(int(tmp3))
    lst.append(demo_number)
    return lst

print(int_to_list(12345)[::-1])

Guess you like

Origin blog.51cto.com/6298641/2482899