Converting integer to digit list

前端 未结 10 1109
渐次进展
渐次进展 2020-11-30 23:45

What is the quickest and cleanest way to convert an integer into a list?

For example, change 132 into [1,3,2] an

10条回答
  •  长情又很酷
    2020-11-30 23:59

    num = list(str(100))
    index = len(num)
    while index > 0:
        index -= 1
        num[index] = int(num[index])
    print(num)
    

    It prints [1, 0, 0] object.

提交回复
热议问题