-4

I am new to python and i was wondering how i could create a list of numbers in python as such

number = 123456
list_to_be_created = [1,2,3,4,5,6]

Thank you in advance

Harsh
  • 23
  • 4

2 Answers2

0
>>> list(range(1, 7))
[1, 2, 3, 4, 5, 6]

If you literally have the number 123456 (i.e. the int value for one hundred twenty three thousand four hundred fifty six) and you want to turn it into a list of its digits, you might do:

>>> number = 123456
>>> list_to_be_created = list(map(int, str(number)))
>>> list_to_be_created
[1, 2, 3, 4, 5, 6]
Samwise
  • 51,883
  • 3
  • 26
  • 36
0

You can try with a list comprehension:

number = 123456
print([int(x) for x in str(number)])

Returns:

[1, 2, 3, 4, 5, 6]
Celius Stingher
  • 14,458
  • 5
  • 18
  • 47