Home > Back-end >  How do I convert a list of integers into an actual list in python [duplicate]
How do I convert a list of integers into an actual list in python [duplicate]

Time:09-21

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]?

CodePudding user response:

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]
  • Related