+ 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

1st Jun 2018, 3:59 PM
ᏳoƊoԲᎮc !
ᏳoƊoԲᎮc ! - avatar
4 Respuestas
+ 9
How about converting the number to String first? Shortest approach I'd prefer: num = 1234567 list = [int(i) for i in str(num)]
1st Jun 2018, 4:05 PM
Dev
Dev - avatar
+ 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
1st Jun 2018, 4:24 PM
ᏳoƊoԲᎮc !
ᏳoƊoԲᎮc ! - avatar
+ 4
Dev Yes its working also Shortest Thanks
1st Jun 2018, 4:06 PM
ᏳoƊoԲᎮc !
ᏳoƊoԲᎮc ! - avatar
+ 2
num = 1234567 list = num.split("")
1st Jun 2018, 4:16 PM
Paul Grasser
Paul Grasser - avatar