List from integers | SoloLearn: Learn to code for FREE!


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

6/1/2018 3:59:58 PM

ᏳoƊoԲᎮc !

4 Answers

New Answer


How about converting the number to String first? Shortest approach I'd prefer: num = 1234567 list = [int(i) for i in str(num)]


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


Dev Yes its working also Shortest Thanks


num = 1234567 list = num.split("")