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.
Answers:
You can split the string , then convert each elements to int –
>>> s = '12 14 17'
>>> list(map(int,s.split()))
[12, 14, 17]
>>>
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.
You can split the string , then convert each elements to int –
>>> s = '12 14 17'
>>> list(map(int,s.split()))
[12, 14, 17]
>>>