How to convert a string filled with numbers to seperate integers in a list?

Question:

So basically I want to convert a string which has multiple numbers to seperate integers in a list.

lst = []
s = '12 14 17'

Basically what I am trying to do is get the lst to be lst = [12,14,17] but I am having difficulty doing this since the string is one whole string and not one string per number.

Asked By: Jack Jone

||

Answers:

You can split the string , then convert each elements to int –


>>> s = '12 14 17'

>>> list(map(int,s.split()))
[12, 14, 17]
>>> 

Answered By: Vaebhav
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.