+ 5
List from integers
We are given a variable: num=1234567 How to make a list of all the integers included in it Like this: >>> [1, 2, 3, 4, 5, 6, 7] The shortest way?? split() is not working in integers
4 Answers
+ 9
How about converting the number to String first?
Shortest approach I'd prefer:
num = 1234567
list = [int(i) for i in str(num)]
+ 5
Paul Grasser Ya have tried it earlier but split() dont work in integers only in strings...đ if you convert it in string then the seperator in split("") is empty so for loop is necessary
Thanks for ur attention
+ 4
Dev Yes its working also Shortest Thanks
+ 2
num = 1234567
list = num.split("")