What is the quickest and cleanest way to convert an integer into a list?
integer
list
For example, change 132 into [1,3,2] an
132
[1,3,2]
Convert the integer to string first, and then use map to apply int on it:
map
int
>>> num = 132 >>> map(int, str(num)) #note, This will return a map object in python 3. [1, 3, 2]
or using a list comprehension:
>>> [int(x) for x in str(num)] [1, 3, 2]