In [1]:
data_string = """
1 2 3 4
11 12 13 14
21 22 23 24
31 32 33 34
41 42 43 44
51 52 53 54
"""
data_string = data_string.strip()
In [2]:
data = [line.split('\t') for line in data_string.split('\n')]
data
Out[2]:
In [3]:
data_f = [list(map(float,line.split('\t'))) for line in data_string.split('\n')]
data_f
Out[3]:
In [4]:
data_i = [list(map(int,line.split('\t'))) for line in data_string.split('\n')]
data_i
Out[4]:
In [5]:
data_i = [list(map(int, row)) for row in data]
data_i
Out[5]:
In [6]:
str0 = "\n".join(",".join(map(str, data_row)) for data_row in data_i)
print (str0)
In [7]:
data_string = """
1
11
21
31
41
51
"""
data_string = data_string.strip()
In [8]:
#data_string = """
#1 2 3 4
#"""
#data_string = data_string.strip()
In [9]:
import re
data = re.split("\t|\n", data_string)
data
Out[9]:
In [10]:
data_f = list(map(float,re.split("\t|\n", data_string)))
data_f
Out[10]:
In [11]:
data_i = list(map(int,re.split("\t|\n", data_string)))
data_i
Out[11]:
In [12]:
str0 = "\n".join(map(str, data_i))
print (str0)
In [13]:
str0 = ",".join(map(str, data_i))
print (str0)