Convert a number to a list of integers

前端 未结 11 1425
渐次进展
渐次进展 2020-12-03 02:44

How do I write the magic function below?

>>> num = 123
>>> lst = magic(num)
>>>
>>> print lst, type(lst)
[1,         


        
11条回答
  •  Happy的楠姐
    2020-12-03 03:27

    You could do this:

    >>> num = 123
    >>> lst = map(int, str(num))
    >>> lst, type(lst)
    ([1, 2, 3], )
    

提交回复
热议问题