-5

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
  • 126
  • 6

2 Answers2

1
>>> 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
  • 68,105
  • 3
  • 30
  • 44
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
  • 17,835
  • 6
  • 23
  • 53