How do I convert a list of integers into an actual list in python

Question:

I have a string of integers for ex. 1 2 3 4 5. How do I convert it into a list like [1, 2, 3, 4, 5]?

Asked By: CoolBoiBS

||

Answers:

You can do this:

int_str = '1 2 3 4 5'

int_list = list(map(int, int_str.split()))

print(int_list)

Output:

[1, 2, 3, 4, 5]
Answered By: Sabil
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.