Simple problem.
I have a number (integer):
mynumber = 1239
I want to convert it into a list of the separate integers like [1,2,3,9]
:
numbersplit = [int(x) for x in mynumber]
But I get the error:
TypeError: 'int' object is not iterable
Why doesn't this work? I'm just making sure the ints
are actually ints
.
However it does work when I wrap it in str
..?
[int(x) for x in str(mynumber)]
[1, 2, 3, 9, 8, 9, 8, 7, 2, 3, 9, 4, 7, 8]
Do lists need to be converted into a string before I can do this?