Convert a number to a list of integers

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

How do I write the magic function below?

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


        
11条回答
  •  离开以前
    2020-12-03 03:27

    You can try this:

    def convert_to_list(number):
        return list(map(lambda x: int(x), str(number)))
    
    convert_to_list(1245)
    

提交回复
热议问题