Answers for "string to list of number"

2

string of numbers to list of integers python

a_string = "1 2 3"
a_list = a_string. split()
#a_list >>> ['1','2','3']
int_list = [int(i) for i in list]
Posted by: Guest on April-17-2021
0

string to list

>>> names='''
...       Apple
...       Ball
...       Cat'''
>>> names
'n      Applen      Balln      Cat'
>>> names_list = [y for y in (x.strip() for x in names.splitlines()) if y]
>>> # if x.strip() is used to remove empty lines
>>> names_list
['Apple', 'Ball', 'Cat']
Posted by: Guest on December-15-2021

Code answers related to "string to list of number"

Python Answers by Framework

Browse Popular Code Answers by Language