-3

Very basic question but how would I change a given input of space separated numbers into a list: e.g.

t = input("Enter some numbers: ")
# for example sake the user inputs: 4 5 10 9 8
# I want to then convert these numbers into a list of [4, 5, 10, 9, 8]
dav123_34
  • 5
  • 3

1 Answers1

0

You can split a string into a list with str.split() and convert into int.

t = "4 5 10 9 8"  # equivalent to t = input("Enter some numbers: ") with 4 5 10 9 8
print([int(v) for v in t.split(" ")])  # [4, 5, 10, 9, 8]
ljmc
  • 4,830
  • 2
  • 7
  • 26